嵌套的急切加载,约束不起作用

时间:2016-06-02 03:52:45

标签: laravel laravel-5 eloquent laravel-5.1 laravel-5.2

我很难使用嵌套约束。有人可以帮助我根据提供的学期分组科目。

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

0 个答案:

没有答案