Query JSON columns in filament tables
Hey, is it possible to query JSON columns in tables ? I've been trying multiple things like
->
, .
, []
without any succes
Is it possible to do something like this Tables\Columns\TextColumn::make('attribute_data->name->value')
?11 Replies
I believe it needs to be a relationship for dot syntax to work. But you can use ->formatStateUsing() to pull the values you need. https://filamentphp.com/docs/2.x/tables/columns/text#custom-formatting
Filament
Text column - Columns - Table Builder - Filament
The elegant TALL stack table builder for Laravel artisans.
formatStateUsing was what I was thinking of thanks for confirmation 😄
tho what if I need two values on the same JSON column ?
If they’re in the same column you can concatenate them into a string and just return it. Could even use HtmlString to output more complicated structure like ul’s
isn't there a way to pull the two values in different columns ?
Maybe, not sure how to do it though since technically a table column represents a database column.
Maybe accessors on the model or virtual columns.
How would you setup virtual columns ?
I'm aware of accessors but not virtual columns it confuses me a bit sorry 😅
Oh I searched I'm sorry I knew that for MySQL I was thinking you were talking about Laravel 😓
Yea. It’s not a Filament thing. But it works if you set them up right. Not sure how a virtual column would work with json data though. Never even thought about it.
Pretty think accessors would be easier to setup and more efficient
I don’t disagree.
Thanks for your help 😁
No worries.