Answer the question
In order to leave comments, you need to log in
Why doesn't lighthouse return data with this condition in the model?
Hello!
There are 3 models: Course, Section, Lesson
They are consecutively "nested" into each other, and are connected via ->hasMany
CourseModel
public function sections() {
return $this->hasMany(Section::class);
}
SectionModel
public function lessons() {
$current_id = $this->getKey('course_id');
return $this->hasMany(Lesson::class, 'section_id', 'section_id')->where('course_id', $current_id);
}
$course = Course::find(1);
$sections = $course->sections;
foreach($sections as $section) {
$lessons = $section->lessons->toArray();
dump($lessons);
}
->where('course_id', $current_id)
Answer the question
In order to leave comments, you need to log in
I found a library that completely copes with my task - https://github.com/topclaudy/compoships
I also found the answer to my question there:
Trying to use where clauses (like in the example below) won't work when eager loading the relationship because at the time the relationship is processed $this->team_id is null.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question