Alright so I'm pretty new to Blade, and I did manage to get all the results that I asked for on my page. Now I want to show only 10 of the total items on my page and I seem to struggle with it, tried the array_slice without any success so far. Any suggestions?
Below the code I'm currently using
{{--@foreach ($element['subs']->slice(0, 10) as $item)--}}
@foreach ($element['subs'] as $item)
<div class="highlight {{ $element['class'] }}">
<div class="el-inner-news">
<div class="image-news">
<a href="{{ $item['news-item']['slug'] }}"> <img src="{{ $item['news-item']['image'] or "/assets/frontend/baywest/images/newsholder.png" }}" class="center-img" alt="{{ $item['news-item']['title'] }}" /> </a>
</div>
<div class="desc-news">
<div class="title-highlight">
<a href="{{ $item['news-item']['slug'] }}">{{ $item['news-item']['title'] }}</a>
</div>
<div class="text-highlight">
{!! $item['news-item']['textfield'] !!}
</div>
<div class="learn-more-news">
<a href="{{ $item['news-item']['slug'] }}">{{ $item['news-item']['read-more'] or "Learn more" }} </a>
</div>
</div>
</div>
</div>
@endforeach
Thanks in advance!
$element['subs']
an array or a collection? – Joseph Silber Oct 28 '15 at 14:13@for($i = 0; $i < 10; $i++) ... @endfor
that can be used, or a foreach with a count (like the answer below). My comment was simply a statement on the strangeness of query for every result, sending those to the view but then only using 10... Just seems odd. – Tim Lewis Aug 19 '16 at 16:38