G
G
Glory2021-05-02 12:18:18
Laravel
Glory, 2021-05-02 12:18:18

How to get a summary selection from two models with similar fields?

There are two very similar models. They have almost the same fields. For example, Cats and Dogs. How is it easier to use laravel to organize a selection of cats and dogs so that they are returned in one request? Thus there will be still conditions of selection and sorting in this request. By name, by price, by country (for example)

In general, they have the same fields, except that one model may have some models associated with it, while the second one may have others. Usually in laravel we return them with the
with('....') construct, and in this case we would also like to get our own nested arrays of related entities for each model.

or is it unrealistic to do and only use raw queries?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin B., 2021-05-02
@Kostik_1993

No way. It was a very t̶u̶p̶y̶m̶ erroneous decision to divide by types of pets if the task was to work with them through a common functionality
. In fact, you should have an Animal model, it has fields and an animal type

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question