Skip to content

Commit

Permalink
Issue with constrained() method used after foreignIdFor(), instead of…
Browse files Browse the repository at this point in the history
… table name when $table parameter is not passed uses column name (#53144)

* Update table name on ForeignIdColumnDefinition.php

* Update ForeignIdColumnDefinition.php

* Update ForeignIdColumnDefinition.php

* Update Blueprint.php

* Update ForeignIdColumnDefinition.php

* Update ForeignIdColumnDefinition.php

* Update ForeignIdColumnDefinition.php

* Update Blueprint.php

* formatting

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
granitibrahimi and taylorotwell authored Oct 15, 2024
1 parent 8048c98 commit f69a736
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Illuminate/Database/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -1039,16 +1039,16 @@ public function foreignIdFor($model, $column = null)
$column = $column ?: $model->getForeignKey();

if ($model->getKeyType() === 'int' && $model->getIncrementing()) {
return $this->foreignId($column);
return $this->foreignId($column)->table($model->getTable());
}

$modelTraits = class_uses_recursive($model);

if (in_array(HasUlids::class, $modelTraits, true)) {
return $this->foreignUlid($column);
return $this->foreignUlid($column, 26)->table($model->getTable());
}

return $this->foreignUuid($column);
return $this->foreignUuid($column)->table($model->getTable());
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Database/Schema/ForeignIdColumnDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public function __construct(Blueprint $blueprint, $attributes = [])
*/
public function constrained($table = null, $column = 'id', $indexName = null)
{
$table ??= $this->table;

return $this->references($column, $indexName)->on($table ?? Str::of($this->name)->beforeLast('_'.$column)->plural());
}

Expand Down

0 comments on commit f69a736

Please sign in to comment.