@php $items = collect($section->items ?? []); // flat array of {thumbnail, mobile_thumbnail, keyword} $layout = $section->layout ?? 1; $carouselId = 'banner-carousel-' . $section->id; /** * Distribute items round-robin into $n column buckets. * e.g. 5 items, n=2 → [[0,2,4], [1,3]] */ $distribute = function(int $n) use ($items) { $buckets = array_fill(0, $n, []); foreach ($items->values() as $i => $banner) { $buckets[$i % $n][] = $banner; } return $buckets; // array of arrays }; @endphp @if($layout == 1) {{-- ── Layout 1: Full-width single carousel ── --}} @elseif($layout == 2) {{-- ── Layout 2: Two carousels side-by-side (col-md-6 each) ── --}} @php $columns = $distribute(2); @endphp
@foreach($columns as $colIdx => $group) @if(count($group)) @php $cid = $carouselId . '-c' . $colIdx; @endphp
@endif @endforeach
@elseif($layout == 3) {{-- ── Layout 3: Three carousels side-by-side (col-md-4 each) ── --}} @php $columns = $distribute(3); @endphp
@foreach($columns as $colIdx => $group) @if(count($group)) @php $cid = $carouselId . '-c' . $colIdx; @endphp
@endif @endforeach
@elseif($layout == 4) {{-- ── Layout 4: Four carousels side-by-side (col-md-3 each) ── --}} @php $columns = $distribute(4); @endphp
@foreach($columns as $colIdx => $group) @if(count($group)) @php $cid = $carouselId . '-c' . $colIdx; @endphp
@endif @endforeach
@endif