Skip to content

Instantly share code, notes, and snippets.

@JeffreyWay
Created August 16, 2013 17:53
Show Gist options
  • Save JeffreyWay/6252012 to your computer and use it in GitHub Desktop.
Save JeffreyWay/6252012 to your computer and use it in GitHub Desktop.
Sometimes, when filtering through a collection and displaying them on the page, you need to wrap every X items within a wrapper. Common examples are when using Bootstrap... Is this the recommended way to do that? Fairly clean as it is, I guess...
@foreach(array_chunk($posts, 3) as $postSet)
<div class="row"> <!-- this div will surround every three posts -->
@foreach($postSet as $post)
<h3>{{ $post['title'] }}</h3>
@endforeach
</div>
@endforeach
@vishnupadmanabhan
Copy link

Try:

@foreach(array_chunk($posts->all(), 3) as $postSet)

instead of:

@foreach(array_chunk($posts, 3) as $postSet)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment