Using Repeater to save as JSON and display in Table

Hi all,
The repeater field is driving me crazy. I use it to save a JSON array in the database but I am not able to display it in a table

I have a model called 'Billing'
Let's say it has only the fields 'id' and 'validity'

This is my code for the Repeater field

Repeater::make('validity')
    ->schema([
        Forms\Components\DatePicker::make('date_from')
                      ->native(false)
                        ->required(),
                Forms\Components\TextInput::make('amount')
                    ->required()
                    ->numeric()
            ->inputMode('decimal')
    ])


The entries in the DB look something like in the screenshot.

Multiple values for 'validity' are stored like this:
 [{"date_from":"2024-02-01","amount":"700"},
{"date_from":"2024-05-13","amount":"750"}]


So when I render the values in the table, there should be multiple rows for each 'Billing'
I only get it to work if I only display one row like this
Tables\Columns\TextColumn::make('validity.0.date_from')
    ->date('d.m.Y'),
Tables\Columns\TextColumn::make('validity.0.amount')
    ->sortable(),

But this works only for the first element in the array.

Can you please help me?
How can I use the Repeater field storing the values as JSON (array) and then display all values in the table.

Thank you so much
db_filament.png
Solution
Thank you very much.
I really wanted to avoid the relationship because json looked so much easier.
It very unfortunate that iz does not work with json.

I will give it a try with relationship.
Thank you
Was this page helpful?