Grammars
3 weeks ago
Blueprint.php
3 weeks ago
Builder.php
3 weeks ago
ColumnDefinition.php
3 weeks ago
ForeignIdColumnDefinition.php
3 weeks ago
ForeignKeyDefinition.php
3 weeks ago
IndexDefinition.php
3 weeks ago
MySqlBuilder.php
3 weeks ago
MySqlSchemaState.php
3 weeks ago
PostgresBuilder.php
3 weeks ago
PostgresSchemaState.php
3 weeks ago
SQLiteBuilder.php
3 weeks ago
SchemaState.php
3 weeks ago
SqlServerBuilder.php
3 weeks ago
SqliteSchemaState.php
3 weeks ago
ForeignIdColumnDefinition.php
49 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWPSCOPED\Illuminate\Database\Schema; |
| 4 | |
| 5 | use IAWPSCOPED\Illuminate\Support\Str; |
| 6 | /** @internal */ |
| 7 | class ForeignIdColumnDefinition extends ColumnDefinition |
| 8 | { |
| 9 | /** |
| 10 | * The schema builder blueprint instance. |
| 11 | * |
| 12 | * @var \Illuminate\Database\Schema\Blueprint |
| 13 | */ |
| 14 | protected $blueprint; |
| 15 | /** |
| 16 | * Create a new foreign ID column definition. |
| 17 | * |
| 18 | * @param \Illuminate\Database\Schema\Blueprint $blueprint |
| 19 | * @param array $attributes |
| 20 | * @return void |
| 21 | */ |
| 22 | public function __construct(Blueprint $blueprint, $attributes = []) |
| 23 | { |
| 24 | parent::__construct($attributes); |
| 25 | $this->blueprint = $blueprint; |
| 26 | } |
| 27 | /** |
| 28 | * Create a foreign key constraint on this column referencing the "id" column of the conventionally related table. |
| 29 | * |
| 30 | * @param string|null $table |
| 31 | * @param string $column |
| 32 | * @return \Illuminate\Database\Schema\ForeignKeyDefinition |
| 33 | */ |
| 34 | public function constrained($table = null, $column = 'id') |
| 35 | { |
| 36 | return $this->references($column)->on($table ?? Str::of($this->name)->beforeLast('_' . $column)->plural()); |
| 37 | } |
| 38 | /** |
| 39 | * Specify which column this foreign ID references on another table. |
| 40 | * |
| 41 | * @param string $column |
| 42 | * @return \Illuminate\Database\Schema\ForeignKeyDefinition |
| 43 | */ |
| 44 | public function references($column) |
| 45 | { |
| 46 | return $this->blueprint->foreign($this->name)->references($column); |
| 47 | } |
| 48 | } |
| 49 |