Barney
Barney
FFilament
Created by Barney on 8/23/2023 in #❓┊help
Select field default value
Hi, Im having trouble with data editing. When I click 'Edit' on a row, the 'region' select field should show the default value, but it keeps showing 'Select an option' instead. What am I doing wrong?
Forms\Components\Select::make('region')
->options(Region::all()->pluck('name', 'id')->toArray())
->default(function (?Model $record) {
if ($record){
return $record->area->region->id;
}
})
->live(),
Forms\Components\Select::make('area_id')
->relationship('area', 'name')
->options(function (Get $get, ?Model $record) {
if($get('region')){
return Area::where('region_id',$get('region'))->get()->pluck('name', 'id');
}
if ($record){
return Area::where('region_id',$record->area->region->id)->get()->pluck('name', 'id');
}
})
->live(),
Forms\Components\Select::make('region')
->options(Region::all()->pluck('name', 'id')->toArray())
->default(function (?Model $record) {
if ($record){
return $record->area->region->id;
}
})
->live(),
Forms\Components\Select::make('area_id')
->relationship('area', 'name')
->options(function (Get $get, ?Model $record) {
if($get('region')){
return Area::where('region_id',$get('region'))->get()->pluck('name', 'id');
}
if ($record){
return Area::where('region_id',$record->area->region->id)->get()->pluck('name', 'id');
}
})
->live(),
6 replies