Skip to content

Commit f69a736

Browse files
Issue with constrained() method used after foreignIdFor(), instead of 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]>
1 parent 8048c98 commit f69a736

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/Illuminate/Database/Schema/Blueprint.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,16 +1039,16 @@ public function foreignIdFor($model, $column = null)
10391039
$column = $column ?: $model->getForeignKey();
10401040

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

10451045
$modelTraits = class_uses_recursive($model);
10461046

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

1051-
return $this->foreignUuid($column);
1051+
return $this->foreignUuid($column)->table($model->getTable());
10521052
}
10531053

10541054
/**

src/Illuminate/Database/Schema/ForeignIdColumnDefinition.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public function __construct(Blueprint $blueprint, $attributes = [])
3737
*/
3838
public function constrained($table = null, $column = 'id', $indexName = null)
3939
{
40+
$table ??= $this->table;
41+
4042
return $this->references($column, $indexName)->on($table ?? Str::of($this->name)->beforeLast('_'.$column)->plural());
4143
}
4244

0 commit comments

Comments
 (0)