Skip to content

Commit

Permalink
Update ForeignIdColumnDefinition.php
Browse files Browse the repository at this point in the history
  • Loading branch information
granitibrahimi authored Oct 13, 2024
1 parent 992810c commit 7295b02
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Illuminate/Database/Schema/ForeignIdColumnDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Illuminate\Database\Schema;

use Illuminate\Support\Str;

class ForeignIdColumnDefinition extends ColumnDefinition
{
/**
Expand Down Expand Up @@ -35,7 +37,11 @@ public function __construct(Blueprint $blueprint, $attributes = [])
*/
public function constrained($table = null, $column = 'id', $indexName = null)
{
return $this->references($column, $indexName)->on($table ?? $this->blueprint->getTable());
if(is_null($table) && is_null($this->table)) {
$table = $this->table;
}

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

/**
Expand Down

0 comments on commit 7295b02

Please sign in to comment.