Custom Filament Table with Query of Left Joined Tables
I have managed to create livewire component with filament table in it as described here:
https://filamentphp.com/docs/3.x/tables/adding-a-table-to-a-livewire-component
In the example, the query for the table is given for a single model. (Product::query())
How can I pass the query for the filament table so that it will take 2 joined tables?
SELECT * FROM employees LEFT JOIN attendances ON employees.id = attendances.employee_id
Solution:Jump to solution
Thanks, Dennis. I think I am getting somewhere. I tried as follow:
```public function table(Table $table): Table
{
return $table
->query(Employee::query()->leftJoin('attendances','employees.id','=','attendances.employee_id'))...
11 Replies
try using
modifyQueryUsing
methodCan you help with an example for the above SQL query? I cannot seem to find the documentation for this method on Filament Table
it's in different location
What should I put in the function body?
whatever you need to add to your query
table
->query(Employee::query())->modifyQueryUsing(fn (Builder $query) => $query->leftJoin(...))? Something like this?
Yes
But when you provide
->query()
already why don’t you put your query there?!Solution
Thanks, Dennis. I think I am getting somewhere. I tried as follow:
It seems to run correctly but the "result" column which supposes to get the data from the "attendances" table is not showing. Did I miss anything? Thanks!
Check what query is actually run and what it returns for example with Laravel Debugbar
Thanks! It is working now. There was a mistake in the "query" that I created.