Table search/filter by json array?

My model has a json attribute which is cast to an array. Filament Table can display this value in a list. However if I add ->searchable() it produces errors, and if I create a SelectFilter it does not effect the query after selection. Is there a trick to searching and filtering by json data attributes?
Solution:
I figured out a partial solution... for the TextColumn::make('myjson.myattribute') and then for SelectFilter::make('myjson->myattribute') works. This still results in an error if you use ->searchable() on the TextColumn but at least the SelectFilter is working with just typecasting the json to array. Was unaware of Eloquent's -> notation for where queries.
Jump to solution
3 Replies
TomEasterbrook98
Filament uses eloquent Models and Collections for these sorts of things. However, you can wor around this with Sushi which creates models by taking in the JSON. https://github.com/calebporzio/sushi If you can share some code very happy to help further
GitHub
GitHub - calebporzio/sushi: Eloquent's missing "array" driver.
Eloquent's missing "array" driver. Contribute to calebporzio/sushi development by creating an account on GitHub.
Solution
FullyLoadedTech
I figured out a partial solution... for the TextColumn::make('myjson.myattribute') and then for SelectFilter::make('myjson->myattribute') works. This still results in an error if you use ->searchable() on the TextColumn but at least the SelectFilter is working with just typecasting the json to array. Was unaware of Eloquent's -> notation for where queries.
FullyLoadedTech
Marking this solved for now, if anyone has further input please let me know!
Want results from more Discord servers?
Add your server
More Posts