Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

LaraBABA's avatar

Best way to save dynamic fields

Hello,

I would like to know if you could give me an idea on this one before I code please. I was thinking about using json to save the data but now I am not sure if this makes sense.

I have 3 tables users, categories, subcategories

each category has the same subcategories(no relations between the 2 as you select any categories and subcategories).

I will generate a dynamic form which will generate all the notifications like this:

Category 1 Subcategory 1 Subcategory 2 Subcategory 3 Subcategory 4 Subcategory 5 Category 2 Subcategory 1 Subcategory 2 Subcategory 3 Subcategory 4 Subcategory 5 category 3 Subcategory 1 Subcategory 2 Subcategory 3 Subcategory 4 Subcategory 5 category 4 Subcategory 1 Subcategory 2 Subcategory 3 Subcategory 4 Subcategory 5

As you can see, this list will increase with time when more categories and subcategories will be added to the article platform.

Next to each of them, I want to add a tick box. So when the user clicks any of it and click "save", I would like to save the actual notifications settings(which I will later use for emailing them).

How would you save this via Eloquent please? Shall I use a single json object or another method?

Thank you.

0 likes
1 reply
drewdan's avatar

You could create a model to store each category type with a relationship to the user. So the user would haveMany of these. And store them in their. Or, possbily easier, would be just to store them as a json object in your database.

Please or to participate in this conversation.