Getting started
Overview
Table Filters
Watch the Rapid Laravel Development with Filament series on Laracasts - it will teach you the basics of adding filters to Filament resource tables.
Filters allow you to define certain constraints on your data, and allow users to scope it to find the information they need. You put them in the $table->filters()
method:
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->filters([
// ...
]);
}
Filters may be created using the static make()
method, passing its unique name. You should then pass a callback to query()
which applies your filter's scope:
use Filament\Tables\Filters\Filter;
use Illuminate\Database\Eloquent\Builder;
Filter::make('is_featured')
->query(fn (Builder $query): Builder => $query->where('is_featured', true))
Available filters
By default, using the Filter::make()
method will render a checkbox form component. When the checkbox is on, the query()
will be activated.
- You can also replace the checkbox with a toggle.
- You can use a ternary filter to replace the checkbox with a select field to allow users to pick between 3 states - usually "true", "false" and "blank". This is useful for filtering boolean columns that are nullable.
- The trashed filter is a pre-built ternary filter that allows you to filter soft-deletable records.
- You may use a select filter to allow users to select from a list of options, and filter using the selection.
- You may use a query builder to allow users to create complex sets of filters, with an advanced user interface for combining constraints.
- You may build custom filters with other form fields, to do whatever you want.
Setting a label
By default, the label of the filter, which is displayed in the filter form, is generated from the name of the filter. You may customize this using the label()
method:
use Filament\Tables\Filters\Filter;
Filter::make('is_featured')
->label('Featured')