Bonjoeri
Bonjoeri
FFilament
Created by Bonjoeri on 2/13/2025 in #❓┊help
Setting two keys from one select field and filling constant data
I have a question regarding forms and filling data. I have the following form definition, i put in comments what im trying to achieve
->form([
Select::make('part_id')
->label('Part')
//this id is now associated to the part_id key, i also want the name column to be bound to another key called 'label'
//I could do this by writing some logic in the mutateDataBeforeSave method but it would involve doing pluck again a second time
//and because this form is deeply nested into the model it would be quite a pain to write
->options(Part::pluck('name', 'id'))
->searchable()
->required(),
TextInput::make('serial_number'),
//the system id is known in the context and i just want it to be added on, do i do that like this?
TextInput::make('system_id')
->hidden(true)
->default($form->getRecord()->id),
]),
->form([
Select::make('part_id')
->label('Part')
//this id is now associated to the part_id key, i also want the name column to be bound to another key called 'label'
//I could do this by writing some logic in the mutateDataBeforeSave method but it would involve doing pluck again a second time
//and because this form is deeply nested into the model it would be quite a pain to write
->options(Part::pluck('name', 'id'))
->searchable()
->required(),
TextInput::make('serial_number'),
//the system id is known in the context and i just want it to be added on, do i do that like this?
TextInput::make('system_id')
->hidden(true)
->default($form->getRecord()->id),
]),
13 replies