我的控制器中有一个代码,它根据条件从数据库中获取数据。我想回显数组中项目的索引public function history($id){ $msg= whatsapp::where('claim_id', $id)->get(); return view('history', compact(['msg''])); }下面是我的每个循环。@foreach($msg as $msg) <tr> <td>{{$msg->id}}</td> <td>{{$msg->created_at}}</td> <td>{{$msg->tel}}</td> <td>{{$msg->message}} <br>{{$msg->files}}</td>> </tr>@endforeach无论消息的 id 是什么,我都希望 numberint 从 1 开始。
1 回答
RISEBY
TA贡献1856条经验 获得超5个赞
如果您只是想在刀片模板中回显数组/集合的索引,请尝试以下操作:
@foreach($msgs as $key => $msg)
<tr>
<td>{{ $key + 1 }}</td>
<td>{{ $msg->id }}</td>
<td>{{ $msg->created_at }}</td>
<td>{{ $msg->tel }}</td>
<td>{{ $msg->message }} <br>{{ $msg->files }}</td>
</tr>
@endforeach
- 1 回答
- 0 关注
- 145 浏览
添加回答
举报
0/150
提交
取消
