Sorting a custom attribute

How would one add a sortable() column that is pointing to an attribute of a model? It shows up fine, but throws an error on sort because the column doesn't exist. As a contrived example: Say I have a "Company" model, which hasMany "CompanyClient"s. On the "Company", there is an attribute called "has_company_clients" which is a boolean. The Filament IconColumn is used to show whether the company has clients or not. I want this column to be sortable
2 Replies
Treebeard
TreebeardOP11mo ago
Another thought would be filtering, can you filter on a custom attribute?
Brian Kidd
Brian Kidd11mo ago
There may be a way to do this using Filament functionality but I would probably just add a scope to the model that counts the relationship and cast it to a boolean. Filament is performing the sort on the query builder.
Want results from more Discord servers?
Add your server