O
O
Outsider V.2017-08-01 09:56:04
Laravel
Outsider V., 2017-08-01 09:56:04

How to organize model hierarchy in Eloquent?

I used to work with Doctrine ORM - everything was obvious there: you create entity classes (with inheritance from the base class, without - no difference) - then you automatically synchronize them with tables (each non-abstract class has its own table).
In Eloquent, nothing is clear: a migration is created for each table, the table defines the model (we do not prescribe properties in the model at all). But what if I have two Pages and Articles models that have properties in common that I want to put into the base Entry abstract model? At the same time, I want to have two tables: Pages and Articles, whose identical fields then will not need to be edited separately. I did not find in the documentation how to implement it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Victor, 2017-08-01
@Audiophile

You can create a base model, then make 2 inherited from it, each of which will use its own table.
Or move the common code to trait.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question