2
我需要爲每個3個附件創建一行。類似於刀片模板佈局結構
@foreach($email->attachment as $attach)
<div class="row">
<div class="col-lg-4"></div>
<div class="col-lg-4"></div>
<div class="col-lg-4"></div>
</div>
@endforeach
<div class="row">
<div class="col-lg-4">1st attachment</div>
<div class="col-lg-4">2nd attachment</div>
<div class="col-lg-4">3rd attachment</div>
</div>
<div class="row">
<div class="col-lg-4">4th attachment</div>
<div class="col-lg-4">5th attachment</div>
<div class="col-lg-4">6th attachment</div>
</div>
等等!我曾搜索過這個問題,但發現了This link,但實際上與我的觀點不同。 感謝
array_chunk需要一個數組而不是一個對象...... ?? – StraightForward 2015-02-23 07:38:32
噢。首先轉換爲數組。看到我更新的答案。 – Laurence 2015-02-23 07:39:56
假設'$ email-> attachment'是一個Laravel集合,您可以簡單地執行'$ email-> attachment-> chunk(3)' – lukasgeiter 2015-02-23 07:45:01