Pass query string parameters to Table Builder in v3
Hi, this is the first question I've asked. I feel like I may be missing something so apologies but I have searched and looked at the docs before asking.
I'm trying to pass a query string parameter to a page using Table Builder. For example, if I have a table of cities in the USA which simply contains:
The name of the City
The State the City is in.
I want to set up a page with a route:
/cities/{state}
If I visit /cities/Florida then I get a page of all the cities in Florida.
I've tried doing this by adding a mount function to my Livewire component:
public function mount($state)
{
$this->state = $state;
}
I then use this in my table function:
return $table
->query(City::where('state', $this->state))
This works initially. The problem is if I then try to sort by a column or search inside that table I get an error:
local.ERROR: Property [$state] not found on component.
I think this is because the mount method is not called when the component re-renders.
How should I structure this query so it works?Solution:Jump to solution
I found the issue and it was something small. I forgot to declare the variable inside the component:
'public $state;'
It's working as expected now. Sorry for wasting everyones time....
3 Replies
If you were to add tabs onto the page, you could utilise the
getTabs()
method like so:-
This will then persist the tab link in the url and you can navigate directly to there.
If you were wanting to do it from filters, you could add ->persistFiltersInSession()
to your table I “think”Solution
I found the issue and it was something small. I forgot to declare the variable inside the component:
'public $state;'
It's working as expected now. Sorry for wasting everyones time.
No problem