Home > Mobile >  query by has many relation where all children must meet the conditions
query by has many relation where all children must meet the conditions

Time:08-15

query with hasMany relation if all children must meet the requirements

for example all products that hasMany pictures where all status = 1 in pictures relation

CodePudding user response:

you need to provide more details of your problem to get best solution. Although you can try something like

Poroduct::has('pictures')->where('status', true);

or

$products = Poroduct::has('pictures');
 $products->where('pictures', function($query){
              $query->  // some conditions
      })

CodePudding user response:

This Laravel documentation explains querying relationships. The first example is probably what you are looking for.

You could try

$products->pictures()->where('status', 1)->get();
  • Related