How to skip first item in a foreach loop in Laravel?
As of Laravel 5.4, whenever you use foreach
or for
within blade files you will now have access to a $loop variable. The $loop variable provides many useful properties and methods, one of them being useful here, for skipping the first iteration. See the example below, which is a much cleaner way of achieving the same result as the other older answers here:
@foreach ($rows as $row)
@if ($loop->first) @continue @endif
{{ $row->name }}<br/>
@endforeach
Assuming that the $aboutcontents
is numeric array just use the good old fashioned for
loop instead of your new fangled foreach
// Notice you start at 1 and your first
// elem is 0 so... ta da... skipped
@for ($i = 1; $i < count($aboutcontents); $i++){
$about = $aboutcontents[$i]; //This is the object
//now use $about as you would
}
Note: I have not used Larvel or blades but based on the docs this should be doable
Try This :
@foreach($aboutcontent as $key => $about)
@if($key > 0){
<div class="col-md-4 text-center">
<div class="thumbnail">
<img id="" class="img-responsive" src="images/{{ $about->aboutimg }}" alt="">
<div class="caption">
<h3>{{ $about->aboutname }}</h3>
<p>{{ $about->aboutinfo }}</p>
</div>
</div>
</div>
@endif;
@endforeach