How to Customize Filament Table Queries in Laravel: Help Needed!
Hello everyone, I hope this isn't a repeated or silly question. I've tried various searches but couldn't find the result I was hoping for.
I have a table connected to a Laravel model, but the data I want to display in the Filament table is completely customized compared to the classic ->get()->all() that I believe Filament uses by default. To clarify, in my GridJobImportResource resource, I'd like the default query to be this:
--- Query in the comment below ---
(It's still static in some parts, but it works, so for testing purposes, it's fine for now).
I've tried everything to override the query, using methods like getEloquentQuery, getTableQuery, or even query directly on the $table variable, but with no success. Is there an easy way to achieve this, or am I forced to use something like Sushi?
Thanks to everyone for your help! Cheers!
3 Replies
Here the query:
I'm trying something like:
but it trigger: Filament\Resources\Pages\ListRecords::getTableRecordKey(): Return value must be of type string, null returned.
Hey dude, Here is what you need to do. First, Filament is expecting a record key associated with each row. That's not the case in a
groupBy
statement. However, you can get around it by defining a key using the method getTableRecordKey
in the resource you are adding the table to. For instance, I have a Table widget and a query using a groupBy
statement. I'm using whatever I'm grouping by as my key as I can guarantee it will be unique for each row. Here is an example that you can modify for your own use: