2 回答

TA贡献1845条经验 获得超8个赞
您可以使用循环变量,如下所示:
//for show post 1-5
@foreach ($posts as $post)
@if($loop->index < 5)
// Your code
@endif
@endforeach
//continue foreach (for show 6-...)
@foreach ($posts as $post)
@if($loop->index > 5)
// Your code
@endif
@endforeach

TA贡献1853条经验 获得超18个赞
您可以在 Blade 中将帖子数据分成 2块
@foreach($posts->chunk(5) as $chunk)
@foreach($chunk as $post)
//.....
@endforeach
//add your banner here after first chunk is rendered
@endforeach
或者单个循环并检查当前迭代
@foreach($posts as $post)
//...........
@if($loop->iteration == 5)
//add your banner here
@endif
@endforeach
- 2 回答
- 0 关注
- 180 浏览
添加回答
举报