Setting table columns based on model's json column

I have this structure:
Form
Response

a form has n responses, 1 response belongs to 1 form

a form has a json field called fields - example:
[{"name": "birthdate", "type": "2", "is_required": true, "placeholder": "Random placeholder test"}]

a response has a field called responses - example:
{"birthdate": "2023-11-25"}


in the form's responses table, i want to set the table's columns dynamically, so it shows all form fields and their responses. im trying this:
(file
app/Filament/Resources/ResponseResource.php
)
public static function table(Table $table): Table
{
    return $table
        ->columns((function (): array {
            $form = Form::findOrFail(1); // 1 is set hardcoded on purpose to test

            return collect()
                ->merge($form->fields)
                ->map(function (array $field) {
                    return Tables\Columns\TextColumn::make($field['name'])
                        ->formatStateUsing(function (Response $record) use ($field) {
                            return $record->responses[str($field['name'])->slug()->toString()]; // this doesnt work ⚠️
                        })
                    ;
                })
                ->merge([
                    Tables\Columns\TextColumn::make('created_at'),
                    Tables\Columns\ToggleColumn::make('is_read')
                        ->onColor(Color::Green)
                        ->offColor(Color::Red)
                    ,
                ])
                ->toArray()
            ;
        })())


which results into this image here, where the birthdate isnt shown. why??? if i just dd
$record->responses[str($field['name'])->slug()->toString()]
in my tinker, it works, it shows ->
"2023-11-25"
Screenshot_2023-11-28_at_10.53.51.png
Was this page helpful?