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
awcodes
awcodes2y ago
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.
skyrowl
skyrowlOP2y ago
formatStateUsing was what I was thinking of thanks for confirmation 😄 tho what if I need two values on the same JSON column ?
awcodes
awcodes2y ago
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
skyrowl
skyrowlOP2y ago
isn't there a way to pull the two values in different columns ?
awcodes
awcodes2y ago
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.
skyrowl
skyrowlOP2y ago
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 😓
awcodes
awcodes2y ago
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.
skyrowl
skyrowlOP2y ago
Pretty think accessors would be easier to setup and more efficient
awcodes
awcodes2y ago
I don’t disagree.
skyrowl
skyrowlOP2y ago
Thanks for your help 😁
awcodes
awcodes2y ago
No worries.
Want results from more Discord servers?
Add your server