somethingElseModel::with('email')->where('stuff', $stuff)->get();
No, there's no such thing. Luckily you can do it by yourself with no effort:
/**
* query scope withWhereHas
*
* @return void
*/
public function scopeWithWhereHas($query, $relation, $field, $operator, $value)
{
$query->with([$relation => function ($q) use ($field, $operator, $value) {
$q->where($field, $operator, $value);
}])->whereHas($relation, function ($q) use ($field, $operator, $value) {
$q->where($field, $operator, $value);
});
}
// then for example:
$something = Something::withWhereHas('someRelation', 'someField', 'like', '%someValue')->get();
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community