F
Filamentβ€’2y ago
Mike Scott

How to access a route parameter in Livewire pagination request?

I've got a resource for customer inquiries, which can be of 5 different types, so I pass the type in a URL query parameter, for example: /inquiries?type=offer I can easily get this query parameter in the request and if no type parameter is passed, it defaults to the first inquiry type, so everything works great. However, when clicking on the pagination for page 2, for example, a Livewire request is sent to the following endpoint: /livewire/message/app.filament.resources.inquiry-resource.pages.list-inquiries But the '?type=offer' query parameter is omitted, so the request falls back to the default type and I get the 2nd page for that, not the original inquiry type. My question is, how can I get the request's query parameters sent in Livewire requests?
5 Replies
Dan Harrin
Dan Harrinβ€’2y ago
you'd need to use the mount() method of the LW component to save the parameter value into a public property, then it persists between requests
Mike Scott
Mike ScottOPβ€’2y ago
Hi Dan, thanks for the fast response. However I just found the answer myself. It's in the LW Table docs in fact - you have to add a public properties to the page and also add the query parameter names to the page's $queryParameters array and Livewire maintains these across requests: https://filamentphp.com/docs/2.x/tables/getting-started#query-string I didn't have to add a mount() method. The public property seems to be updated to match the query parameter value.
Filament
Getting started - Table Builder - Filament
The elegant TALL stack table builder for Laravel artisans.
Mike Scott
Mike ScottOPβ€’2y ago
Hi Dan, so I got the query parameter to work but I want to set the page title to include the inquiry type. However, the page title is static and if I try to change it in the mount() method, for example, I get an error because the route (which now includes the type which I added to the title) doesn't exist. So how can I change the page title to match the type of inquiry that's being displayed?
Dennis Koch
Dennis Kochβ€’2y ago
You can use the getTitle() method
Mike Scott
Mike ScottOPβ€’2y ago
Shoulda thought of that πŸ˜„ Thanks Dennis!
Want results from more Discord servers?
Add your server