@php // Desktop images (teammate's layout) + mobile counterparts kept index-aligned. // mobile[i] pairs with desktop[i]; a null means "use the desktop image on phones". $desktopRaw = collect([$banner->banner_image])->merge($banner->additional_images ?? []); $mobileRaw = collect([$banner->mobile_banner ?? null])->merge($banner->additional_mobile_images ?? []); $allImages = collect(); $allMobile = collect(); foreach ($desktopRaw as $idx => $img) { if (!empty($img)) { $allImages->push($img); $allMobile->push($mobileRaw[$idx] ?? null); } } $allImages = $allImages->values(); $allMobile = $allMobile->values(); $allUrls = $banner->image_urls ?? []; $alignments = $banner->web_image_alignment; // null = legacy layout $isFullWidth = ($banner->web_width ?? 'container') === 'full_width'; // Build alignment-based row groups when alignment data is present $rows = []; if ($alignments !== null) { $imgCount = $allImages->count(); $i = 0; while ($i < $imgCount) { $align = $alignments[$i] ?? 'full'; $nextAlign = $alignments[$i + 1] ?? null; if ($align === 'half' && $nextAlign === 'half') { $rows[] = [ 'type' => 'pair', 'images' => [$allImages[$i], $allImages[$i + 1]], 'mobiles' => [$allMobile[$i] ?? null, $allMobile[$i + 1] ?? null], 'urls' => [$allUrls[$i] ?? null, $allUrls[$i + 1] ?? null], ]; $i += 2; } else { $rows[] = [ 'type' => 'single', 'image' => $allImages[$i], 'mobile' => $allMobile[$i] ?? null, 'url' => $allUrls[$i] ?? null, ]; $i++; } } } @endphp @if ($allImages->isNotEmpty())
@if ($alignments !== null) {{-- Alignment-based layout: each row is either a single full-width image or a side-by-side pair --}} @foreach ($rows as $row) @if ($row['type'] === 'single') @else
@foreach ($row['images'] as $pairIdx => $image) @endforeach
@endif @endforeach @else {{-- Legacy layout: main image full-width, additional images in 2-column grid --}} @php $primaryImage = $allImages->first(); $primaryMobile = $allMobile->first(); $secondaryImages = $allImages->slice(1); $primaryUrl = ($allUrls[0] ?? null) ?: ($banner->link_url ?? null); @endphp @if ($secondaryImages->isNotEmpty())
@foreach ($secondaryImages as $imageIndex => $image) @php $imgUrl = ($allUrls[$imageIndex + 1] ?? null) ?: ($banner->link_url ?? null); $imgMobile = $allMobile[$imageIndex] ?? null; @endphp @endforeach
@endif @endif
@endif