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 關注
- 182 瀏覽
添加回答
舉報