E
E
Eugene2019-07-18 21:26:01
Laravel
Eugene, 2019-07-18 21:26:01

How to make a selection of data with conditions in a related table "Many to many"?

Perhaps somehow I did not write the title correctly, but I will try to describe in more detail.
An example is a model where supplier data is stored (Model1). The second model stores a set of all properties (Model2). There is a many-to-many relationship (with the conventional name Relation1).
The question is how, when selecting Model1, to make what would be the condition in the many-to-many relationship?

// Как мне при работе с Eloquent запросом указать условие для выборки для связи в Relation1.
// Т.е. как мне выбрать поставщика с у которого есть определенное свойство?
$result = Model1:with('Relation1')->get();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Wells, 2019-07-18
@atachrus

whereHas (documentation)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question