platform icon indicating copy to clipboard operation
platform copied to clipboard

select for the ENUM field from database

Open schel4ok opened this issue 10 months ago • 2 comments

I try to make select for the database ENUM field $table->enum('priority', ['низкий', 'средний', 'высокий'])->default('низкий');, but none of the example fields from ExampleFieldsScreen class can't do the job.

I tried these option

    Select::make('task.priority')
        ->title('Приоритет задачи'),

    Input::make('task.priority')
        ->title('Приоритет задачи')
        ->datalist(['низкий', 'средний', 'высокий'])
        ->horizontal(),

    Relation::make('task')
        ->fromModel(Task::class, 'priority')
        ->title('Select for Eloquent model'),

schel4ok avatar Apr 13 '25 20:04 schel4ok

Sorry. I forget to $task->priority = $request->input('task.priority'); in create method, so in general this code works

    Input::make('task.priority')
        ->title('Приоритет задачи')
        ->datalist(['низкий', 'средний', 'высокий'])
        ->horizontal(),

But maybe there is a way not to indicate datalist and get them from database directly to avoid mistype?

schel4ok avatar Apr 13 '25 21:04 schel4ok

@schel4ok use php enums to store possible options or, alternatively, you can try to adapt it to your needs https://stackoverflow.com/questions/2350052/how-can-i-get-enum-possible-values-in-a-mysql-database

But in think php enums better

bald-cat avatar Apr 15 '25 14:04 bald-cat