Skip to content

Commit e7b27d0

Browse files
committed
Adding the possibility to set the default value of a column.
1 parent 5ad27f5 commit e7b27d0

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ $table->unique(['login', 'status']);
141141
$table->column('description')->string(50)->null();
142142
```
143143

144+
**Set the default value of a column:**
145+
146+
```php
147+
$table->column('enabled')->bool()->default(true);
148+
```
149+
144150
**Create a foreign key**
145151

146152
```php

src/FluidColumnOptions.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ public function primaryKey(?string $indexName = null): FluidColumnOptions
9090
return $this;
9191
}
9292

93+
public function default($defaultValue): FluidColumnOptions
94+
{
95+
$this->column->setDefault($defaultValue);
96+
return $this;
97+
}
98+
9399
public function then(): FluidTable
94100
{
95101
return $this->fluidTable;

tests/FluidColumnOptionsTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public function testOptions()
3535
$columnOptions->autoIncrement();
3636
$this->assertSame(true, $dbalColumn->getAutoincrement());
3737

38+
$columnOptions->default(42);
39+
$this->assertSame(42, $dbalColumn->getDefault());
40+
3841
$this->assertSame($posts, $columnOptions->then());
3942

4043
$columnOptions->column('bar');

0 commit comments

Comments
 (0)