( , ). whereHas . , , . whereHas, , .
, ( , ):
public function scopeWithAndWhereHas($query, $relation, $constraint){
return $query->whereHas($relation, $constraint)
->with([$relation => $constraint]);
}
:
User::withAndWhereHas('submissions', function($query) use ($id){
$query->where('taskid', $id);
})->get();