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.
No description
6 Replies
awcodes
awcodesβ€’5mo ago
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.
Davide Cariola
Davide CariolaOPβ€’5mo ago
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?
Jany
Janyβ€’5mo ago
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
Dennis Koch
Dennis Kochβ€’5mo ago
Virtual Columns are a SQL concept.
Davide Cariola
Davide CariolaOPβ€’5mo ago
Thanks everyone. Tomorrow I'll work on it and let you know!
Davide Cariola
Davide CariolaOPβ€’5mo ago
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 πŸ˜„
No description
No description
No description
Want results from more Discord servers?
Add your server