Query string in pagination
Hi,
From an edit resource I have a button that links to another list (Audits) resource with 2 parameters like so:
In my audit list resource I then filter all the audits (this is a polymorphic table and stores the model class name and the model id - note that this is using Laravel Auditing - https://laravel-auditing.com/) based on the 2 GET parameters that are passed like so:
Which all works fine on the first load. However, when I change the pagination my request object is reset to null and therefore the above query no longer works.
With Laravel you can do
::paginate()->withQueryString()
but I can't find anything similar with Filament.
Any ideas to ensure that the request object sticks around, or a better solution to this problem that requires no sending of things in the request?
Thanks πLaravel Auditing
Laravel Auditing
Laravel Auditing allows you to record changes to an Eloquent model's set of data by simply adding its trait to your model.
5 Replies
Instead of appliying a query add a where filter by default then build the url with the tablefilter
i.e.
?tableFilters[date_range][date_from]=2024-04-18&tableFilters[date_range][date_to]=2024-04-26
Do you have a link to the docs regarding the where filter? Cheers
https://filamentphp.com/docs/3.x/tables/filters/getting-started
Build the filters as normal, apply them and copy the query string.
Brill - I got this working (and it works nicely with the pagination). The only downside is that these filters appear to the user which I wouldn't want. I set the filter as
->hidden()
which does hide it from view, but it also ignores the filter from the table results.Ok, I didn't appreciate you want filters by url that are not shown. Either hide them by css class on the table and targetted css.
Or on the mount, if the request contains the filters, set them in state and apply them as you originally did?