F
Filament16mo ago
Magooh

Searchable table with nested values

Is there a way to make the table search look for (nested) values which are not defined as a column? Lets say we have a table with orders. I want to look up all orders which have order lines with a certain type (i.e. virtual product). Is this possible?
6 Replies
Magooh
MagoohOP16mo ago
If I could extend the search query and write a custom query that'd totally work for me as well. Tried to use the public static function getEloquentQuery for this but that doesn't have access to the search query
Patrick Boivin
Patrick Boivin16mo ago
Which version of Filament?
Magooh
MagoohOP16mo ago
V2! Sorry, should've inlcuded that
Patrick Boivin
Patrick Boivin16mo ago
Instead of getEloquentQuery() on the resource, you could explore around applySearchToTableQuery() in the List page class
Magooh
MagoohOP16mo ago
This looks like what I am looking for. Thanks. Will explore further For others running into the same problem:
// ListOrders.php

protected function applySearchToTableQuery(Builder $query): Builder
{
if (filled($searchQuery = $this->getTableSearchQuery())) {
return $query->whereHas('orderLines', function (Builder $query) use ($searchQuery) {
$query->where('type', '=', $searchQuery);
});
}

return $query;
}
// ListOrders.php

protected function applySearchToTableQuery(Builder $query): Builder
{
if (filled($searchQuery = $this->getTableSearchQuery())) {
return $query->whereHas('orderLines', function (Builder $query) use ($searchQuery) {
$query->where('type', '=', $searchQuery);
});
}

return $query;
}
Will mark as done!
toeknee
toeknee15mo ago
A heads up this won't work in V3, since getTableSearchQuery doesn't exist. Currently working to find a solution
Want results from more Discord servers?
Add your server