F
Filament5mo ago
Grogu

How to make a custom model attribute column searchable and sortable?

Hey! I have a getFullNameAttribute() method on my user model - how do i display that full name column in a resource, and then allow searching and sorting on it?
5 Replies
awcodes
awcodes5mo ago
You can’t search or sort on model attributes as it’s not part of the eloquent query. You would need to have virtual db columns on the table to make that work.
Grogu
GroguOP5mo ago
I'm not familliar with virtual db columns...interesting!
awcodes
awcodes5mo ago
Can’t find it at the moment, but iirc there’s something about them in the docs.
Grogu
GroguOP5mo ago
No worries, thanks I'll look into it! 🙂
toeknee
toeknee5mo ago
Virtual Columns in MySQL and Use cases.
Discover MySQL 5.7 virtual columns, which compute data using expressions. Learn their syntax, use cases, benefits, and indexing for optimized queries.

Did you find this page helpful?