@php $artists = $artworksData[0]->artist_array; $totalArtists = count($artists); $columns = min(4, ceil($totalArtists / 15)); // max 4 columns, assuming 15 rows per column $rowsPerColumn = ceil($totalArtists / $columns); // Chunk the array vertically $columnsData = array_fill(0, $columns, []); foreach ($artists as $index => $artist) { $colIndex = intdiv($index, $rowsPerColumn); $columnsData[$colIndex][] = $artist; } @endphp

Featured Artists

@foreach ($columnsData as $col) @endforeach
@foreach ($col as $artist)
{{ $artist }}
@endforeach