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
The entries in the DB look something like in the screenshot.
Multiple values for 'validity' are stored like this:
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 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
I only get it to work if I only display one row like this 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
Solution:Jump to 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....
3 Replies
Since the table is trying to work with simple arrays (no key value pairs) you'll need to format the column state and play around with the values from the validity column, which is an associative array. Here's an example where I flatten the key value pairs into a simple array of strings. Then, I
use ->bulleted()
to format each array item into a bulleted list.
Although, if you need to keep more than one column of information that is related to billings, I would suggest moving away from JSON columns and instead create a validity relationship (HasMany) and then integrate the repeater to work with said relationship.
https://filamentphp.com/docs/3.x/forms/fields/repeater#integrating-with-an-eloquent-relationship
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