K
K
knowledge2018-05-14 10:38:36
Laravel
knowledge, 2018-05-14 10:38:36

Is it better to have one model for content or for each one of your own?

I plan to have various kinds of content on the site, for example, news, interviews, translations, etc., in general, there is a lot of it, about 10 varieties
, and so I thought about whether it would be better to make one general model, of the Content type, where there will be a type field that defines what kind of content or is it better to make separate models for news, interviews, etc.
in principle, the fields there will be plus / minus related
news
heading - description - news
in the interview
heading - interview (the description field can be left empty if there is one model)
how is it customary to do in such cases?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Y
Yan-s, 2018-05-14
@Yan-s

If the logic is the same or slightly different, then one model will suffice. This is a more convenient option, especially if the content record selections are mixed. But you need to be sure that in the future there will be no need for a fundamental separation.

L
Lander, 2018-05-14
@usdglander

You can put the same fields in one model (Entity type), and the rest of the fields can be connected via DI.

I
iljaGolubev, 2018-05-14
@iljaGolubev

If you work through Active Record, then it is better for each entity to have a separate model (class). Such duplication of code is not always bad - it depends on the complexity of each model and on differences in their functionality.
At the same time, you can have one Contents table in the database in which all types of content are stored, and to filter each model, use global scope , for example.
Connect the same methods of models through traits.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question