F
Filamentβ€’5mo ago
Vladimir

Table Colum Json - Array to string conversion error

in user table there is a settings column that is json. Tables\Columns\TextColumn::make('settings') throws Array to string conversion.
Tables\Columns\TextColumn::make('settings')->formatStateUsing(function (array $state) ....
Tables\Columns\TextColumn::make('settings')->formatStateUsing(function (array $state) ....
formatStateUsing - throws array to string conversion error Tried to cast in user model as protected $cast = [ 'settings' => array ] Also throws array to string conversion error Could not find anything in table builder docs. Not a single mention. I am pretty sure that there is some way to do it, and wondering how as it is not possible that is not possible πŸ˜„ Anyone can help?
6 Replies
varovas
varovasβ€’5mo ago
That's because you cannot print array as string. What do you want to do with that json? Just to print json string in a column?
Vladimir
VladimirOPβ€’5mo ago
yes
varovas
varovasβ€’5mo ago
What is you settings column type? JSON? Basically it should work like the example below. Just remove settings => array from casts.
TextColumn::make('settings')
TextColumn::make('settings')
Vladimir
VladimirOPβ€’5mo ago
thank you for your reply. in my first line i described it and show code example as same as you tried to help. i agree that 'should' work. the thing is that from some reason, unknown to me, just does not. πŸ™‚ there was no array in casts before . i added it trying to find a workable solution. However, i think i will try diffrent approach and make a custom table column, so i can do other things with settings too. I think that would be a good idea. Thank you, again πŸ™‚
Firebat
Firebatβ€’4mo ago
you could just json encode then in the formatstateusing if you want to print the whole json
toeknee
toekneeβ€’4mo ago
Look at spatie settings πŸ˜‰
Want results from more Discord servers?
Add your server