A
A
Anatoly2017-02-10 14:03:12
ORM
Anatoly, 2017-02-10 14:03:12

How to compose a Laravel ORM query?

Good day.
There are 2 tables, one with a list of establishments, the other with the relationship of establishments to features.
It is necessary to choose establishments with the indicated features.
Institutions - institutions
id | good | ... | ... |
Relationship table - attitudes
feature_id | institution_id

$attitudes = [1, 2, 3];
$institutions = Institutions::where('good', 1);

$institutions = $institutions->whereHas('attitudes', function($query) use ($attitudes) {
         $query->whereIn('feature_id', $attitudes);
});

You need to select all the institutions that have the attribute "1" and "2" and "3"
With this request, he gives me all the institutions that have either "1" or "2" or "3"

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question