【发布时间】:2022-07-21 17:10:05
【问题描述】:
我有三个模型,一个是数据透视表(grade_studentattendances),另一个模型是(grades and studentattendances)。我只想显示学生从一年级到八年级的数据。
我的查看代码是:
<table border="1">
<tr>
<th>Id</th>
<th>Full name</th>
<th>Roll no</th>
<th>Date</th>
<th>Status</th>
<th>Grade</th>
</tr>
@php
$i=1;
@endphp
@foreach($studentattendance as $item)
@php $grades=$item->Grade; @endphp
<tr>
<th>{{$item->id }}</th>
<th>{{$item->name}} </th>
<th>{{$item->roll_no}}</th>
<th>{{$item->date}}</th>
<th>{{$item-> status}}</th>
<th>
@foreach($grades as $grade)
{{$grade->class_name }}
@endforeach
</th>
</tr>
@endforeach
</table>
我的控制器是:
public function sattend()
{
$studentattendance=studentattendance::all();
return view('primaryhead.s_attend',compact('studentattendance'));
}
我只是想以表格的形式显示一年级到八年级的学生
【问题讨论】:
标签: php mysql laravel pivot-table