我很难使用嵌套约束。有人可以帮助我根据提供的学期分组科目。
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'] as $subject)
<tr>
<td>{{ $subject->subject_code }}</td>
<td>{{ $subject->subject_description }}</td>
<td>{{ $subject->units }}</td>
<td></td>
<td>98</td>
</tr>
@endforeach