Filament Table Filters

Hi Guys, First off, I am pretty new to Filament, absolutely loving it so far. This might be very easy, I just dont know the solution. I have a couple of filters on my table: ->filters([ Filter::make('Your Account') ->query(fn (Builder $query): Builder => $query->where('AGENT', Auth::user()->getAgentAccnum())) ->checkbox() ->default(), The filter works well, But I would like the filter to be applied permanently. And the User should not be able to remove the filter. I have tried the ->hidden() approach at the end of the filter, but this seems to not apply the filter, and just hides it. I have tried to add the where clause in getEloquentQuery() function. And that does apply it, but it then messes with my column's sorting functionality. Is there a way to prevent the filter from being de-selected? Or is there a better place to filter the initial results?
Solution:
Why a filter? I would just apply the scope to the model personally? so if you are filter the records based on a users access level you can scope the model to only ever return data where
Jump to solution
4 Replies
Solution
toeknee
toeknee8mo ago
Why a filter? I would just apply the scope to the model personally? so if you are filter the records based on a users access level you can scope the model to only ever return data where
zander9255
zander92558mo ago
Hi Toeknee! Thank you so much, this does seem like a much better approach!
toeknee
toeknee8mo ago
Then you can have the filter and show the filter to people with access to it, and those people wouldn't have the scope applied.
zander9255
zander92558mo ago
Edit: This did the trick, leaving the URL here in case it helps someone else in future https://laravel.com/docs/11.x/eloquent#query-scopes
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
Want results from more Discord servers?
Add your server