laravel - Nested eager loading with constraint not working -
i having hard time using nested constraint. can me group subjects based on semester offered.
mycontroller
public function show($id) { $student = student::with(['course', 'course.curriculum', 'course.curriculum.subjects' => function($query){ $query->groupby('sem_offered'); }])->findorfail($id); return view('students.show', compact('student')); }
show.index
@foreach($student->course->curriculum->subjects['first first-sem'] $subject) <tr> <td>{{ $subject->subject_code }}</td> <td>{{ $subject->subject_description }}</td> <td>{{ $subject->units }}</td> <td></td> <td>98</td> </tr> @endforeach