I have a foreach loop that has data. I am using a foreach loop to echo the data out into a table.
@foreach($data as $key)
<tr>
<td>{{$key->option_name}}</td>
</tr>
@endforeach()
This gives me a table with one column and 1 row of data. This table only has one data field and instead of one long list of data, i want it spread over 4 columns.
I would like to have 4 columns so the table looks nice and neat.
Please see attached example image.
What i am trying to achieve, after the 4 columns if there is more data then it starts the next row with 4 columns.


instead of creating a new row and column for each data point, simply don't create a new row by putting the
troutside the loop. Assuming your$datais a collection, we can use thechunk(size: 4)method to create collections of specified size out of the original$data.This way every
$sizeitems we create a new row with$sizecolumns.If
$datais an array we can use thearray_chunkfunction instead.