Skip to content

Commit 8323276

Browse files
browner12tegos
authored andcommitted
handle all Enum types for default values (laravel#57040)
by using the internal `enum_value()` helper, we can handle both `UnitEnum`s and `BackedEnum`s, similar to how we do elsewhere in the framework. we check for `UnitEnum`, because it is the broader of the 2 types.
1 parent a793089 commit 8323276

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/Illuminate/Database/Schema/Grammars/Grammar.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
namespace Illuminate\Database\Schema\Grammars;
44

5-
use BackedEnum;
65
use Illuminate\Contracts\Database\Query\Expression;
76
use Illuminate\Database\Concerns\CompilesJsonPaths;
87
use Illuminate\Database\Grammar as BaseGrammar;
98
use Illuminate\Database\Schema\Blueprint;
109
use Illuminate\Support\Fluent;
1110
use RuntimeException;
11+
use UnitEnum;
12+
13+
use function Illuminate\Support\enum_value;
1214

1315
abstract class Grammar extends BaseGrammar
1416
{
@@ -477,8 +479,8 @@ protected function getDefaultValue($value)
477479
return $this->getValue($value);
478480
}
479481

480-
if ($value instanceof BackedEnum) {
481-
return "'".str_replace("'", "''", $value->value)."'";
482+
if ($value instanceof UnitEnum) {
483+
return "'".str_replace("'", "''", enum_value($value))."'";
482484
}
483485

484486
return is_bool($value)

0 commit comments

Comments
 (0)