Last active
July 13, 2023 07:51
-
-
Save ericlbarnes/5771365 to your computer and use it in GitHub Desktop.
Limit a foreach with Laravel blade
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@foreach (array_slice($posts->toArray(), 0, 5) as $post) | |
<h1>{{ $post['title'] }}</h1> | |
@endforeach |
@foreach ($posts->slice(0, 5) as $post)
<h1>{{ $post->title }}</h1>
@endforeach
It works perfect for me.
@foreach ($posts->take(5) as $post)
<h1>{{ $post->title }}</h1>
@endforeach
is much cleaner, and works great
Yes sir ;) @ron4stoppable
@foreach($skills->user->take(5) as $user)
this one is great
@foreach (array_slice($data, 0, 4) as $content)
thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just needed this for a dashboard view where we need the same data in different places, just modified a bit by limiting what is shown. Thanks for the solution, worked perfectly!