UniTue's avatar

Custom Attributes: should I use EAV or JSON or Create Tables?

I built a system where users can design formulars over the UI, create workflows which are related to the formulars and store them.

In the current state only admins can create formulars, because I create a new table in my database while creating a new formular. The admin can create a new formular, and add attributes to the formular by using different data types: String, DateTime, JSON, Boolean, Integer.. a.s.o. By saving the formular, I add the attributes to an existing "formular_attributes" table and i create a new table with the name of the formular.

By now this works fine and it's pretty fast. But as I informed myself about options to solve this issue, I heard some comments that it's not recommended to create new tables (on-the-fly). And of course I create a new Model (on-the-fly) by writing a PHP file into the Laravel directory.

As I see, not a lot of people use EAV in Laravel. A lot of posts are unanswered, or commented with: "I didn't have done this before. Why so?"

When solving this use-case with a JSON attribute, mostly the answers are: "It's possible, but building up complex queries can be a pain."

So, my questions are:

  1. What speaks against creating tables / models on the fly?
  2. Is it better to use EAV in Laravel while creating dynamic attributes and dynamic models? What would be the advantages / disadvantages ?
  3. What would be the advantages / disadvantages when using JSON for storing additional attributes?

Thank you all in advance.

0 likes
0 replies

Please or to participate in this conversation.