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,
            ]);
    }
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;
}
Was this page helpful?