我有这个刀片模板
<div class="row-fluid">
@foreach($courses as $course)
<div class="span3 learn">
Content
</div>
@endforeach
输出
<div class="row-fluid">
<div class="span3 learn">
Content
</div>
<div class="span3 learn">
Content
</div>
<div class="span3 learn">
Content
</div>
<div class="span3 learn">
Content
</div>
<!-- this span should be in a spearted row-fluid div -->
<div class="span3 learn">
Content
</div>
</div>
此代码添加了一个span3大小的块我使用Twitter bootstrap reponsive 我需要在行 - 流体div中为每4个跨度添加行液体
我希望输出像这样
<div class="row-fluid">
<div class="span3 learn"> Content </div>
<div class="span3 learn"> Content </div>
<div class="span3 learn"> Content </div>
<div class="span3 learb"> Content </div>
</div>
<div class="row-fluid">
<div class="span3 learn"> Content </div>
<div class="span3 learn"> Content </div>
<div class="span3 learn"> Content </div>
<div class="span3 learn"> Content </div>
</div>
我不知道如何在laravel @foreach
中实现这一目标先谢谢
答案 0 :(得分:27)
您可以使用array_chunk
上的$courses->all()
将其拆分为4个组,然后创建嵌套的@foreach。像这样:
@foreach (array_chunk($courses->all(), 4) as $courseRow)
<div class="row-fluid">
@foreach ($courseRow as $course)
<div class="span3 learn">...</div>
@endforeach
</div>
@endforeach