4 months ago

Relationship or column?

Posted 4 months ago by johncarter

I have a Product model with any number of attributes. Each product has one of each of these attributes. E.g. such as colour, size, gender, and say plus 8-10 more.

Can people tell me what seems more logical out of the following options:

Option 1 Eloquent relationship per attribute, e.g. models for every attribute: Colour, Size

Option 2 Use a column on the same table with snake cased value. Then use some sort of lookup array to get the human readable name per snake_cased attribute.

Option 3 An eloquent ProductAttribute which allow multiple attributes per product.

Option 1 seems like a lot of tables. Option 2 seems hacky. Option 3 seems convoluted and might cause unnecessarily slow queries.

Any opinions / best practices for this seemingly common situation?

Please sign in or create an account to participate in this conversation.