Skip to content

Commit

Permalink
fix connection issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Sairahcaz committed Apr 14, 2023
1 parent 05ffef6 commit 189b216
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/DynamicModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,15 @@ private function getDynamicTableValues(): array

$currentDBConnection = Schema::getConnection()->getName();

$connection = Schema::getConnection();
if ($currentDBConnection !== $this->dynamicConnectionName) {
Schema::connection($this->dynamicConnectionName);
$connection = Schema::connection($this->dynamicConnectionName)->getConnection();
}

if (! Schema::hasTable($this->dynamicTableName)) {
if (! $connection->getSchemaBuilder()->hasTable($this->dynamicTableName)) {
throw DynamicModelException::tableDoesNotExist($this->dynamicTableName);
}

// get primary key, incrementing and key type
$connection = Schema::getConnection();

$table = $connection->getDoctrineSchemaManager()->listTableDetails($this->dynamicTableName);

if (! $primaryKey = $table->getPrimaryKey()) {
Expand Down

0 comments on commit 189b216

Please sign in to comment.