Skip to content

Commit 5f72d5b

Browse files
authored
Merge pull request #3788 from Laravel-Backpack/fix-enum-sqlite
Fix for enum field on SQLite database
2 parents e019150 + 364df50 commit 5f72d5b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/app/Models/Traits/HasEnumFields.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ public static function getPossibleEnumValues($field_name)
2020

2121
$instance = new static(); // create an instance of the model to be able to get the table name
2222
$connectionName = $instance->getConnectionName();
23-
$type = DB::connection($connectionName)->select(DB::raw('SHOW COLUMNS FROM `'.$table_prefix.$instance->getTable().'` WHERE Field = "'.$field_name.'"'))[0]->Type;
23+
24+
try {
25+
$type = DB::connection($connectionName)->select(DB::raw('SHOW COLUMNS FROM `'.$table_prefix.$instance->getTable().'` WHERE Field = "'.$field_name.'"'))[0]->Type;
26+
} catch (\Exception $e) {
27+
abort(500, 'Enum field type is not supported - it only works on MySQL.');
28+
}
29+
2430
preg_match('/^enum\((.*)\)$/', $type, $matches);
2531
$enum = [];
2632
foreach (explode(',', $matches[1]) as $value) {

0 commit comments

Comments
 (0)