Filter for calculated field
Hello everyone!
In a filament table I have a field called TTF (Topical Trust Flow) which has a dynamic numeric value depending on the topic chosen by the user.
I would like to perform a filter on this value, but I need the filter not to be "custom" in the Livewire component page but rather to be a filament filter. The point is that this calculated field is not saved in the database and so I would not know where to retrieve this information with the classic
query
method.
Thank you very much for any help you can give me. Attached is the code for the column.6 Replies
Currently, because filters are tied directly to eloquent, I think the only way to do this would be with a virtual column on the table.
Hi, thank you for the response! I was wandering about an SQL view.
When you talk about a virtual column you intend in filament or in the DB?
You can also adjust main query to calculate that column, or have virtual sql column or sql view, or havinng job to calculate that column from time to time
Virtual Columns are a SQL concept.
Thanks everyone. Tomorrow I'll work on it and let you know!
I decided to do this with an SQL View. Il post the code so maybe it could be useful for other people.
1st image - migration for sql view
2nd image - model for sql view
3rd image - query for filter considering a "MinMax" type of field
If anyone has some feedbacks, I'll be thankful.
Also thanks to @awcodes, @Jany and @Dennis Koch to make me learn about virtual columns π