I am trying to use the relationship as its shown in the code:
$lesson = Lesson::with(['teacher.teacherLessons' => function($teacherLesson){
$teacherLesson->whereHas('category.courses', function($course){
$course->where('id', DB::raw('`lessons`.`course_id`'));
});
}]);
i want to use the same id that was loaded by the main query raw, instead to use DB::raw
,
how to get it?
The whereColumn
/orWhereColumn
method are there for just such a scenario.
The
whereColumn
method may be used to verify that two columns are equal:
$course->whereColumn('id', 'lessons.course_id');