octal's avatar
Level 1

Model with user defined fields and properties

I would like to create a new Laravel app that will let users manage some items. For each item, users will have to possibility to add additional properties/fields.

Is there a good way to do that with Laravel/Eloquent? when a user add a new field to an item, is there a special API to add such fields to the model and (most problematic) to handle it automatically in forms validation? (I know I have to create the form dyanamically). Did anyone dealed with such problem?

Regards

0 likes
2 replies
tykus's avatar

I solved a similar problem using the Entity-Attribute-Value approach, but I'm not sure I'd recommend it. Wiring everything up was not trivial.

Depending on the nature of the data, the extent to which you need to query the user-defined fields, and your database supporting it, you could use a JSON column to provide the flexibility you need.

Please or to participate in this conversation.