F
Filamentβ€’3mo ago
Adam Holmes

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:
Actions\Action::make(name: 'Audit Logs')
->url(function() {
return route('filament.app.resources.audit-logs.index', ['resource' => ListItemResource::getModel(), 'id' => $this->record->id]);
}),
Actions\Action::make(name: 'Audit Logs')
->url(function() {
return route('filament.app.resources.audit-logs.index', ['resource' => ListItemResource::getModel(), 'id' => $this->record->id]);
}),
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:
return $table
->modifyQueryUsing(function (Builder $query) {
$query->where('auditable_type', request()->get('resource'));
$query->where('auditable_id', request()->get('id'));
})
return $table
->modifyQueryUsing(function (Builder $query) {
$query->where('auditable_type', request()->get('resource'));
$query->where('auditable_id', request()->get('id'));
})
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
toeknee
toekneeβ€’3mo ago
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
Adam Holmes
Adam Holmesβ€’3mo ago
Do you have a link to the docs regarding the where filter? Cheers
toeknee
toekneeβ€’3mo ago
Adam Holmes
Adam Holmesβ€’3mo ago
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.
No description
toeknee
toekneeβ€’3mo ago
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?