Courses

Filament 3 From Scratch: Practical Course

Table Filters for Select and Dates

You're reading a FREE PREVIEW of a PREMIUM course.
Summary of this lesson:
- Creating select filters
- Implementing custom date filters
- Configuring filter layouts
- Managing multiple filters

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...

The full lesson is only for Premium Members.
Want to access all 24 lessons of this course? (101 min read)

You also get:

  • 76 courses
  • Premium tutorials
  • Access to repositories
  • Private Discord