How can I use where to filter in queries with that relate multiple tables.
$a = App\A::with(['bs', 'bs.cs', 'bs.cs.ds'])->get();
how can I make 'bs.cs.ds' attributeX = 40 and 'bs.cs' attributeY = true
How can I use where to filter in queries with that relate multiple tables.
$a = App\A::with(['bs', 'bs.cs', 'bs.cs.ds'])->get();
how can I make 'bs.cs.ds' attributeX = 40 and 'bs.cs' attributeY = true
I greet you and I tell you with the following example; that when you do eagger loading and you need to establish conditions, do it in the following way
$users = App\Category::with(['posts' => function ($query) {
$query->where('posts_title', 'like', '%backend%')
->where('posts_status', 1);
}])->get();
As you can notice in the associative arrangement I first pass the name of the method that I refer to in my example (posts), later I create a anonymous function that receives as parameter to $ query which is going to allow access to the methods where I require by means of the operator
->
as you observe I can declare as many as you need and at final placeget();
I put it with an example that I hope will serve as a reference to adapt it to your needs
For further reference, please visit this link