php - 如何在 laravel 中使用 2 foreach
问题描述
如何在 laravel 中使用 2 foreach?
横幅 div 不能包含在 forach 中。因为布局被破坏了。
//for show post 1-5
@foreach ($posts as $post)
//.................
@endforeach
//for banner
<div>
...............
</div
//continue foreach (for show 6-...)
@foreach ($posts as $post)
//.................
@endforeach
解决方案
您可以使用循环变量,如下所示:
//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
推荐阅读
- python-3.x - ArgumentError: hasproperty of NULL PyObject using PyPlot in julia 1.5.3 in JupyterNotebook
- r - 模型适合 Lavaan CFA。这段代码有什么问题?
- shell - 从最后一个字符开始的字符串 shell 脚本中的子字符串
- web - 网站未从 www 重定向到 https
- spring-security - 永远不会调用 Spring 安全过滤器
- opencv - OpenCV 文本检测
- django - Django url前缀关联
- android - 未解决的参考:requireLensFacing | 安卓工作室
- java - 获取 Firestore 中已删除文档的 ID
- django - 重定向后Django表单不可见