这是我的代码:
StudentController.php
public function show($id)
{
$student = Student::with('course', 'course.curriculum', 'course.curriculum.subjects')->findOrFail($id);
return view('students.show', compact('student'));
}
show.blade.php
<div class="panel-body">
<table class="table table-bordered">
<thead>
<tr>
<th>Course Code</th>
<th>Descriptive Title</th>
<th>Units</th>
<th>Prerequisites</th>
<th>Grade</th>
</tr>
</thead>
<tbody>
@foreach($student->course->curriculum->subjects as $subject)
<tr>
<td>{{ $subject->subject_code }}</td>
<td>{{ $subject->subject_description }}</td>
<td>{{ $subject->units }}</td>
<td></td>
<td>98</td>
</tr>
@endforeach
</tbody>
</table>
</div>
答案 0 :(得分:2)
查看slice()
方法。文档示例:
$collection = collect([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
$slice = $collection->slice(4);
$slice->all();
// [5, 6, 7, 8, 9, 10]