B
B
bernex2015-06-22 09:56:34
ORM
bernex, 2015-06-22 09:56:34

How do you choose the right inherited models in Laravel?

The products table has a type_id column.
I want to inherit from Product and make different types of products: FirstProduct, NativeProduct, SuperProduct.
Because they all depend on this type in the database, but have different pricing options or the like.
How to do it correctly so that when selecting a set of models, models with the correct class are returned?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dzham, 2015-06-22
@Dzham

Use polymorphic relations
laravel.su/docs/5.0/eloquent#polymorphic-relations

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question