Answer the question
In order to leave comments, you need to log in
Laravel fetch conditions with?
Hello everyone, there is such a structure: Categories -> Parameters -> Parameter values
I get all this in one request: Category::with('params.values')->get();
How can I add conditions specifically for params?
The documentation has an example with conditions:
$users = User::with(['posts' => function($query)
{
$query->where('title', 'like', '%первое%');
}])->get();
Answer the question
In order to leave comments, you need to log in
$users = User::with(['posts' => function($query)
{
$query->where('title', 'like', '%первое%');
},
'foo',
'bar' => function($query){
// bar query
}])->get();
Category::with('params.values')->whereHas('params', function($query){
$query->where('something', 'foobar');
})->get();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question