Home > Blockchain >  query inside with eloquent
query inside with eloquent

Time:06-05

image address has location and total number of users.

    Users::with(['address'=>function($query){
    $query->where('location', 'NAXAL');
    $query->order By('total');
    }])->get();

this query will return all the users and on relation whose query did not match will be null .I want to pull only those users which do not null value on relation and order By accordingly.

CodePudding user response:

You can use whereHas condition

Users::whereHas('address', function($query){
$query->where('location', 'NAXAL');
$query->order By('total');
})->get();
  • Related