Hidden::make('label'), Select::make('part_id') ->label('Part') ->options(fn() => Part::pluck('name', 'id')) ->searchable() ->afterStateUpdated(fn(Forms\Set $set, $state) => $set('label', Part::find($state)->name)) ->required(),
//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'))
public static function form(Form $form): Form { return $form ->schema([ AdjacencyList::make('part_locators') ->label('Parts') ->maxDepth(10) ->form([ Select::make('part_id') ->label('Part') ->options(Part::pluck('name', 'id')) ->searchable() ->required(), TextInput::make('serial_number'), ]), Select::make('customer_id') ->required() ->label('Customer') ->default(request()->query('customer_id')) ->options(Customer::pluck('company', 'id')) ->searchable(), TextInput::make('system_name')->required(), RichEditor::make('system_remarks'), DatePicker::make('latest_software_update'), ]); }