2 回答

TA貢獻(xiàn)1845條經(jīng)驗(yàn) 獲得超8個(gè)贊
您可以使用循環(huán)變量,如下所示:
//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貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超18個(gè)贊
您可以在 Blade 中將帖子數(shù)據(jù)分成 2塊
@foreach($posts->chunk(5) as $chunk)
? ? ? ? @foreach($chunk as $post)
? ? ? ? ? ? //.....
? ? ? ? @endforeach?
? ? //add your banner here after first chunk is rendered
@endforeach
或者單個(gè)循環(huán)并檢查當(dāng)前迭代
@foreach($posts as $post)
? ? //...........
? ? @if($loop->iteration == 5)
? ? ? ? //add your banner here?
? ? @endif
@endforeach
- 2 回答
- 0 關(guān)注
- 176 瀏覽
添加回答
舉報(bào)