-
Hello, maybe the title will make you confused because usually e.g : // filter something for private lesson only.
// $query is from `lesson` table.
$query->where('is_private', true, function ($subQuery) {
// make sure only pick data that has classrooms for private lesson only.
$subQuery->has('classrooms');
// or using whereHas example
$subQuery->whereHas('classrooms', function ($deptQuery) {
$deptQuery->where('course_id', $course->id);
});
}); i don't know how to achieve this more efficient with eloquent or raw query, but if you want to provide the example with the existing laravel features, I am very grateful you had help. to make this easier to understand : where if but also check for relations availability. ModelName::whereRaw('IF (`is_private` = true, CHECK_RELATIONSHIP)->get(); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I think you just want to chain the two wheres, since there's no // using has
$query->where('is_private', true)->has('classrooms'); // using whereHas
$query->where('is_private', true)->whereHas('classrooms', function ($deptQuery) {
$deptQuery->where('course_id', $course->id);
}); |
Beta Was this translation helpful? Give feedback.
I think you just want to chain the two wheres, since there's no
or
involved.