Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select field on enum type when using generate #15218

Open
wants to merge 9 commits into
base: 4.x
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,24 @@ public function getFormComponents(?string $model = null, array $exceptColumns =
default => TextInput::class,
};

if (isset($type['name']) && $type['name'] === 'enum') {
$componentData['type'] = Select::class;
$options = array_combine(
$type['values'],
array_map(
fn ($value) => (string) str($value)
->kebab()
->replace(['-', '_'], ' ')
->ucfirst(),
$type['values']
)
);
$componentData['options'] = [$options];
if ($column['default']) {
$componentData['default'] = [$this->parseDefaultExpression($column, $model)];
}
}

if (str($componentName)->endsWith('_id')) {
$guessedRelationshipName = $this->guessBelongsToRelationshipName($componentName, $model);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ protected function parseColumnType(array $column): array

$values = is_null($values) ? [] : match ($type) {
'string', 'char', 'binary', 'bit' => ['length' => (int) $values[0]],
'enum' => ['values' => array_map(fn ($value) => trim($value, "'"), $values)],
default => [],
};

Expand Down
Loading