Table (or Table lookalike) with an Eloquent collection

Since I'm using Filament tables in other places in my project, for style consistency I'd like to be able to have Filament tables that simply display data from an already queried Eloquent collection without having to hit the DB again. Is this possible without having to implement Sushi or some other third party package?
Solution:
Ok, as sometimes happens when I finally put a question in writing, I figured out a better way to do things. I'm gonna mark this as solved.
Jump to solution
8 Replies
awcodes
awcodes5mo ago
I’m not following. All tables use an eloquent query.
BillTheFish
BillTheFish5mo ago
Yes I understand that. I want to use an Eloquent Collection that is the result of a query instead of doing another DB call to get data I've already retrieved.
awcodes
awcodes5mo ago
Sounds like you’re just not using the right query for your table. An eloquent query is just that. And tables allow you to modify the query. So you’re either using an eloquent query or something like sushi which isn’t an actual eloquent query. But you mentioned both so I’m confused as to what you are actually trying to do.
BillTheFish
BillTheFish5mo ago
You query: Model::<some query>->get() This gives you an Eloquent Collection. I'd like to use a subset of this collection in a Filament styled table. No filters, no actions, just an ordered display of data in tabular format.
403gtfo
403gtfo5mo ago
(Not an expert so huuuuuuuuuuuge grain of salt. ) But from what I see people trying to do the same, suggested using a thing called sushi(?) if you really need to use the collection as var. Otherwise you can use this below in your resource: public static function getEloquentQuery(): Builder{ return parent::getEloquentQuery() <some query> } Hope this helps, but again.. I am stumbling through this like all of us 😛
403gtfo
403gtfo5mo ago
Example:
No description
BillTheFish
BillTheFish5mo ago
Yah. I can transform the Collection back into a query but that will hit the DB again. For my use case it's probably ok to do that but it's not the best practice.
Solution
BillTheFish
BillTheFish5mo ago
Ok, as sometimes happens when I finally put a question in writing, I figured out a better way to do things. I'm gonna mark this as solved.