© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•17mo ago•
2 replies
spacedev

Use Filament Table Filters With Sushi

Hello, I created a simple resource and my table has these filters.

->filters([
                Filter::make('Period')
                    ->form([
                        Flatpickr::make('from')
                        ->default(Carbon::now()->format('Y-m'))
                            ->monthSelect()
                            ->beforeOrEqual('to')
                            ->maxDate(now()->firstOfMonth())
                            ->required(true),
                        Flatpickr::make('to')
                            ->default(Carbon::now()->format('Y-m'))
                            ->monthSelect()
                            ->afterOrEqual('from')
                            ->maxDate(now()->lastOfMonth())
                            ->required(),
                    ])
                    ->default()
                    ->columns(2)
->filters([
                Filter::make('Period')
                    ->form([
                        Flatpickr::make('from')
                        ->default(Carbon::now()->format('Y-m'))
                            ->monthSelect()
                            ->beforeOrEqual('to')
                            ->maxDate(now()->firstOfMonth())
                            ->required(true),
                        Flatpickr::make('to')
                            ->default(Carbon::now()->format('Y-m'))
                            ->monthSelect()
                            ->afterOrEqual('from')
                            ->maxDate(now()->lastOfMonth())
                            ->required(),
                    ])
                    ->default()
                    ->columns(2)


In the Manage Class I have overridden the method getTableQuery() to set from and to variable in the Model and use them in the Sushi getRows() method.

protected function getTableQuery(): ?Builder
{
if(isset($this->tableFilters['Period']['from']) && isset($this->tableFilters['Period']['to'])){
ModelName::setPeriod($this->tableFilters['Period']['from'],$this->tableFilters['Period']['to']);
}
return ModelName::query();
}

This is my model

class Name extends Model
{

    use \Sushi\Sushi;

    protected static $from;
    protected static $to;

    public function getRows()
    {
        info(self::$from);
        info(self::$to);
        // The query
    }

    public static function setPeriod($from, $to): Builder
    {
        self::$from = $from;
        self::$to = $to;
        return self::query();
    }

    protected function sushiShouldCache()
    {
        return false;
    }
}
class Name extends Model
{

    use \Sushi\Sushi;

    protected static $from;
    protected static $to;

    public function getRows()
    {
        info(self::$from);
        info(self::$to);
        // The query
    }

    public static function setPeriod($from, $to): Builder
    {
        self::$from = $from;
        self::$to = $to;
        return self::query();
    }

    protected function sushiShouldCache()
    {
        return false;
    }
}


When I set the from and to dates using the filter, data is filtered using the previous value of these filters instead of the current one.
Any suggestions?
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Filament Table Filters
FilamentFFilament / ❓┊help
2y ago
Using Sushi with Filament Table and refresh the data
FilamentFFilament / ❓┊help
16mo ago
Way To Use Filters Outside a Filament Table?
FilamentFFilament / ❓┊help
2y ago
Sushi + table search
FilamentFFilament / ❓┊help
2y ago