F
Filament16mo ago
Wim

I have a select box with currently shows a list of all animals

Select::make('animal_id')
->relationship('animal', 'name')
Select::make('animal_id')
->relationship('animal', 'name')
However I don't want to show all animals. I just want to show animals that have a status (=database column) of 'ready'. Can this be done in Filament v3 I was trying this to no success:
Select::make('animal_id')
->relationship('animal', 'name')
->options(function (Closure $get) {
return Animal::where('status', $get('animal_id'))->pluck('name', 'id');})
Select::make('animal_id')
->relationship('animal', 'name')
->options(function (Closure $get) {
return Animal::where('status', $get('animal_id'))->pluck('name', 'id');})
3 Replies
Kenneth Sese
Kenneth Sese16mo ago
relationship() can take a query so you can do something like ->relationship('animal', 'name', modifyQueryUsing: fn (Builder $query) => $query->where('status', $get('animal_id')) Be sure to import Builder
Wim
WimOP16mo ago
Thanks! Works like a charm
Want results from more Discord servers?
Add your server