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:
Solution:Jump to solution
Eg. On your ListResource page:
```php
public function table(Table $table): Table
{...
9 Replies
What are you trying to do? Don't detail the technical implementation, what is the use-case you're looking to support?
In the index page, I am trying to filter records according to authenticated user role.
Admins can see all records.
Restaurant admins can only see records belong to them.
Initially, I can get it to filter records correctly according to getEloquentQuery(). But the filter doesn't work anymore once I click 'reset' button on the filter modal. In other words, when restaurant admin clicks on the reset filter button, all records are shown even if it doesn't belong to them (as shown in the image attached.
This should be the expected behaviour when clicking on reset filter button. It should query records according to getEloquentQuery()
Anyways, I just found the solution,
getEloquentQuery() should have this line:
instead of:
appreciate you trying to help @Oddman π»
Right, you want to modifyBaseQuery, I believe.
Solution
Eg. On your ListResource page:
That's not 100% right code, you'll need to fix it - but that's kinda what you want.
That works, thanks bro!
Remember to mark the right answer π