Table and getting counts of records (groupBy)
I have a table widget. It generates a list of mobile device models and the number of mobiles of that given model. In doing this I can't search or sort because the query isn't something filament can modify for searching and sorting. I get the 'column: count doesn't exist`. Is there a "Filament" approved way of accomplishing this?
This is my widget:
See the image for an example of how it looks. Is this the proper way of accomplishing this?
3 Replies
Nope. If you look at the eloquent statement in my post, you'll see that I'm not dealing with a relationship count. The model column is not a relationship to another table. In my table of mobile devices, there is a column 'model'. I want to groupBy that model string in the mobile table and display the count of records that match that string.
Perhaps there is a way to use the filament
count()
method to achieve what I need? If so, I misunderstood your answer and could use a little clarification. Thank you!Ok. I've seen people manipulate collections and make the resource utilise those. Personally though I create database views for this sort of thing, and then as far as filament\laravel are concerned, its just a table. Obviously don't try anything other than reading it, but assume for a widget, you wouldn't need to.