通过 $loop 判断该数据是否是最先 / 最后的数据:
@foreach ($users as $user)
@if ($loop->first)
This is the first iteration.
@endif
@if ($loop->last)
This is the last iteration.
@endif
<p>This is user {{ $user->id }}</p>
@endforeach
Copy
当然他还有其他可用属性例如: $loop->iteration 和 $loop->count.