Newbie question about reusing filters

Just under 10 hours using Fillament, so maybe obvious and I am missing it, but is there a common Filament way of reusing filters or this is just fine?

<?php

namespace App\Filament\Resources\Shared\Filters;

use Filament\Tables\Filters\Filter;
use Illuminate\Database\Eloquent\Builder;

abstract class UpcomingFilter
{
    public static function make(): Filter
    {
        return Filter::make('upcoming')
            ->translateLabel('Upcoming')
            ->query(fn (Builder $query): Builder => $query->where('published_at', '>', now()))
            ->toggle();
    }
}


Basically creating a class and pulling it from there in any resource which uses that filter.
Solution
You’re on the right track and this will probably work. But I would extend the Filter class itself instead on returning a filter instance. Then you can define the modifiers inside the setUp() method. And then you can just use it in your table as UpcomingFilter::make() without having to give it a name.
Was this page helpful?