File tree Expand file tree Collapse file tree 3 files changed +21
-0
lines changed
src/Illuminate/Database/Schema/Grammars Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace Illuminate \Database \Schema \Grammars ;
4
4
5
+ use BackedEnum ;
5
6
use Doctrine \DBAL \Schema \AbstractSchemaManager as SchemaManager ;
6
7
use Doctrine \DBAL \Schema \TableDiff ;
7
8
use Illuminate \Contracts \Database \Query \Expression ;
@@ -309,6 +310,10 @@ protected function getDefaultValue($value)
309
310
return $ this ->getValue ($ value );
310
311
}
311
312
313
+ if ($ value instanceof BackedEnum) {
314
+ return "' {$ value ->value }' " ;
315
+ }
316
+
312
317
return is_bool ($ value )
313
318
? "' " .(int ) $ value ."' "
314
319
: "' " .(string ) $ value ."' " ;
Original file line number Diff line number Diff line change 7
7
use Illuminate \Database \Schema \Blueprint ;
8
8
use Illuminate \Database \Schema \ForeignIdColumnDefinition ;
9
9
use Illuminate \Database \Schema \Grammars \MySqlGrammar ;
10
+ use Illuminate \Tests \Database \Fixtures \Enums \Foo ;
10
11
use Mockery as m ;
11
12
use PHPUnit \Framework \TestCase ;
12
13
@@ -623,6 +624,13 @@ public function testAddingString()
623
624
624
625
$ this ->assertCount (1 , $ statements );
625
626
$ this ->assertSame ('alter table `users` add `foo` varchar(100) null default CURRENT TIMESTAMP ' , $ statements [0 ]);
627
+
628
+ $ blueprint = new Blueprint ('users ' );
629
+ $ blueprint ->string ('foo ' , 100 )->nullable ()->default (Foo::BAR );
630
+ $ statements = $ blueprint ->toSql ($ this ->getConnection (), $ this ->getGrammar ());
631
+
632
+ $ this ->assertCount (1 , $ statements );
633
+ $ this ->assertSame ('alter table `users` add `foo` varchar(100) null default \'bar \'' , $ statements [0 ]);
626
634
}
627
635
628
636
public function testAddingText ()
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Illuminate \Tests \Database \Fixtures \Enums ;
4
+
5
+ enum Foo: string
6
+ {
7
+ case BAR = 'bar ' ;
8
+ }
You can’t perform that action at this time.
0 commit comments