Β© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filamentβ€’3y agoβ€’
11 replies
Jia Yong Lim

Reset Filter according to getEloquentQuery

Hi, I'm new to filament, I'm facing an issue on resetting filters, appreciate any help πŸ˜…

Expected behaviour:
Reset filter on index page and get it to query according to getEloquentQuery()

Current behaviour:
Clicking on reset button will reset everything and ignore queries in getEloquentQuery().

Code:
    public static function getEloquentQuery(): Builder
    {
        $operation = last(explode('.', Route::currentRouteName()));
        $query =  parent::getEloquentQuery();

        if ($operation == 'index')
        {
            $authUser = auth()->user();

            if ($authUser->role == 'restaurant-admin') {
                $rewardIds = Reward::where('restaurant_id', $authUser->restaurant_id)->pluck('id'); 
                $query =  $query->whereIn('reward_id', $rewardIds);
            }
        }

        return $query
            ->withoutGlobalScopes([
                SoftDeletingScope::class,
            ]);
    }
    public static function getEloquentQuery(): Builder
    {
        $operation = last(explode('.', Route::currentRouteName()));
        $query =  parent::getEloquentQuery();

        if ($operation == 'index')
        {
            $authUser = auth()->user();

            if ($authUser->role == 'restaurant-admin') {
                $rewardIds = Reward::where('restaurant_id', $authUser->restaurant_id)->pluck('id'); 
                $query =  $query->whereIn('reward_id', $rewardIds);
            }
        }

        return $query
            ->withoutGlobalScopes([
                SoftDeletingScope::class,
            ]);
    }
Solution
Eg. On your ListResource page:

public function table(Table $table): Table
{
        $table = parent::table($table);

        if ($authUser->role == 'restaurant-admin') {
            $rewardIds = Reward::where('restaurant_id', $authUser->restaurant_id)->pluck('id'); 

            $table->modifyQueryUsing(fn(QueryBuilder $query) => $query->whereIn('reward_id', $rewardIds));
        }

        return $table;
}
public function table(Table $table): Table
{
        $table = parent::table($table);

        if ($authUser->role == 'restaurant-admin') {
            $rewardIds = Reward::where('restaurant_id', $authUser->restaurant_id)->pluck('id'); 

            $table->modifyQueryUsing(fn(QueryBuilder $query) => $query->whereIn('reward_id', $rewardIds));
        }

        return $table;
}
Jump to solution
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

how can i show/hide filter according to another filter ?
FilamentFFilament / β“β”Šhelp
3y ago
reset filter fields
FilamentFFilament / β“β”Šhelp
2y ago
Change chart type according to the selected filter
FilamentFFilament / β“β”Šhelp
12mo ago
how to hide other field in select table filter according to another filter
FilamentFFilament / β“β”Šhelp
7mo ago