F
Filament8mo ago
Tjiel

Parameter being null after table action

I have a widget that refreshes the page with a custom parameter. I use this parameter to manipulate a different widget, which needs a page refresh. And to update the getTableQuery method.
protected function getTableQuery(): Builder
{
if (Request::query('location')) {
switch (Request::query('location')){
case 'all': return parent::getTableQuery();
case 'allDeleted': {
return Asset::onlyTrashed();
}
default: {
$location = Location::findOrFail(Request::query('location'));
$assetIds = $location->assets->pluck('id')->toArray();
return parent::getTableQuery()->whereIn('id', $assetIds);
}
}
}
dd(Request::query('location'));
$location = Location::first();
if ($location) {
$assetIds = $location->assets->pluck('id')->toArray();
return parent::getTableQuery()->whereIn('id', $assetIds);
}
return parent::getTableQuery();
}
protected function getTableQuery(): Builder
{
if (Request::query('location')) {
switch (Request::query('location')){
case 'all': return parent::getTableQuery();
case 'allDeleted': {
return Asset::onlyTrashed();
}
default: {
$location = Location::findOrFail(Request::query('location'));
$assetIds = $location->assets->pluck('id')->toArray();
return parent::getTableQuery()->whereIn('id', $assetIds);
}
}
}
dd(Request::query('location'));
$location = Location::first();
if ($location) {
$assetIds = $location->assets->pluck('id')->toArray();
return parent::getTableQuery()->whereIn('id', $assetIds);
}
return parent::getTableQuery();
}
This is working fine on the initial loading of the page, as you would expect the Request::query('location') is present and it applies the correct filters. The problem comes when trying to do a table action like delete, restore or any custom action. Then it is null, as i can see using the dd method. Why might this be and how can i make it so it will detect the location.
5 Replies
krekas
krekas8mo ago
it's how livewire works. you don't have the request. can't you use native table filters?
Tjiel
TjielOP8mo ago
I need to reload the page for the mapping tool, I could not find a good way achieve this using the native filters. Maybe if there is a way to change the table filters from the inside of the widget on load it could work.
krekas
krekas8mo ago
What do you need to map? You return two times query without params so no filters. Add filters for other conditions
Tjiel
TjielOP8mo ago
The two times query without params are for when there is no location yet created, or for when the location parameter is all
krekas
krekas8mo ago
which means no filters selected
Want results from more Discord servers?
Add your server