where in laravel with with

1

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

    
asked by César Alejandro M 29.06.2018 в 20:53
source

1 answer

1

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 place get();

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

    
answered by 29.06.2018 в 22:40