Skip to content

Commit

Permalink
use $this->table in bindsDynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
Sairahcaz committed Apr 3, 2023
1 parent 943edff commit eaa0afc
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/DynamicModelBinding.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ public function bindDynamically(): void
$this->setConnection(self::$dynamicDBConnection);
}

if (! Schema::hasTable(self::$dynamicTableName)) {
throw DynamicModelException::tableDoesNotExist(self::$dynamicTableName);
}

// set the table for the dynamic model
$this->setTable(self::$dynamicTableName);

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

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

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

if (! $primaryKey = $table->getPrimaryKey()) {
throw DynamicModelException::primaryKeyDoesNotExist();
}

$primaryKeyName = $primaryKey->getColumns()[0];
$primaryColumn = $connection->getDoctrineColumn(self::$dynamicTableName, $primaryKeyName);
$primaryColumn = $connection->getDoctrineColumn($this->table, $primaryKeyName);

$this->primaryKey = $primaryColumn->getName();
$this->incrementing = $primaryColumn->getAutoincrement();
Expand Down

0 comments on commit eaa0afc

Please sign in to comment.