Skip to content

Commit a6aa917

Browse files
committed
Fix for enum field on SQLite database
Enum field may take 'options' in case the db is sqlite
1 parent df9bcd2 commit a6aa917

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/app/Models/Traits/HasEnumFields.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +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-
$connectionName = $instance->getConnectionName();
23-
$type = DB::connection($connectionName)->select(DB::raw('SHOW COLUMNS FROM `'.$table_prefix.$instance->getTable().'` WHERE Field = "'.$field_name.'"'))[0]->Type;
22+
$connection = $instance->getConnection();
23+
24+
// SQLite doesn't support enum
25+
if ($connection->getConfig('driver') === 'sqlite') {
26+
return null;
27+
}
28+
29+
$type = $connection->select(DB::raw('SHOW COLUMNS FROM `'.$table_prefix.$instance->getTable().'` WHERE Field = "'.$field_name.'"'))[0]->Type;
2430
preg_match('/^enum\((.*)\)$/', $type, $matches);
2531
$enum = [];
2632
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']);
7+
$possible_values = $entity_model::getPossibleEnumValues($field['name']) ?? $field['options'];
88
@endphp
99
<select
1010
name="{{ $field['name'] }}"

0 commit comments

Comments
 (0)