SelectFilter by 2 level relationship

I want to make a SelectFilter by country in a table where I show vehicles.

The data model is as follows:

Vehicle
  • id
  • name
  • place_id
Place
  • id
  • name
  • country_id
Country
  • id
  • code
  • name
That is, a Vehicle belongs to a Place and a Place has a Country.

My current code is as follows, the filter shows it but the changes are not applied:

SelectFilter::make('place.country.code')
    ->label(__('Country'))
    ->options(fn () => Country::pluck('name', 'code')->toArray())
    ->multiple()
    ->searchable()
    ->preload(),

Thanks
Solution
Filament
Filament is a collection of tools for rapidly building beautiful TALL stack apps, designed for humans.
Was this page helpful?