Skip to content

Commit fea3d13

Browse files
committed
Proper error description on enum field
1 parent 43e5d20 commit fea3d13

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/app/Models/Traits/HasEnumFields.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ public static function getPossibleEnumValues($field_name)
1919
$table_prefix = Config::get('database.connections.'.$default_connection.'.prefix');
2020

2121
$instance = new static(); // create an instance of the model to be able to get the table name
22-
$connection = $instance->getConnection();
22+
$connectionName = $instance->getConnectionName();
2323

24-
// SQLite doesn't support enum
25-
if ($connection->getConfig('driver') === 'sqlite') {
26-
return null;
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.');
2728
}
2829

29-
$type = $connection->select(DB::raw('SHOW COLUMNS FROM `'.$table_prefix.$instance->getTable().'` WHERE Field = "'.$field_name.'"'))[0]->Type;
3030
preg_match('/^enum\((.*)\)$/', $type, $matches);
3131
$enum = [];
3232
foreach (explode(',', $matches[1]) as $value) {

src/resources/views/crud/fields/enum.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
@include('crud::fields.inc.translatable_icon')
55
@php
66
$entity_model = $crud->model;
7-
$possible_values = $entity_model::getPossibleEnumValues($field['name']) ?? $field['options'];
7+
$possible_values = $entity_model::getPossibleEnumValues($field['name']);
88
@endphp
99
<select
1010
name="{{ $field['name'] }}"

0 commit comments

Comments
 (0)