Now let's return to our tables and see how to filter the data. You have already seen the searchable()
for columns, but we can add a more complex global filter.
Remember, in the ProductResource, we have this array empty by default:
app/Filament/Resources/ProductResource.php:
return $table ->columns([ // ... ]) ->filters([ // <- THIS ONE ])
It's time to fill it in!
You can define the filters that would appear in the top-right corner of the table.
The most simple example provided in the docs would render a checkbox filter:
->filters([ Tables\Filters\Filter::make('is_featured') ->query(fn (Builder $query): Builder => $query->where('is_featured', true))])
You need to provide a query that would filter by that checkbox.
But in our case, we don't have a checkbox field. We have Product status
with three possible options. For this case...