dolor3sh4ze
dolor3sh4ze

Reputation: 1165

Taking values from a certain number Laravel

I have a database with images related to one product, and I'd like to take those images there only from the second one.

The code to my view is this. I put a line for each image

@foreach($allImages as $image)
                    <a href="" class="item-thumb"> <img src="{{ asset('merchants/images/products/' . $image->image) }}" alt="little picture"></a>
                    @endforeach

I hope I'm clear enough on what I'd like to do...

Upvotes: 0

Views: 43

Answers (2)

Divyank
Divyank

Reputation: 788

@foreach($allImages->skip(1) as $image)
    <a href="" class="item-thumb"> <img src="{{ asset('merchants/images/products/' . $image->image) }}" alt="little picture"></a>
@endforeach

This will skip the first record

Upvotes: 4

Khalid Khan
Khalid Khan

Reputation: 3185

You can do something like this to skip the first image in the array

@foreach($allImages as $image)
    @if($loop->first){
        @continue;
    }
    else{
        <a href="" class="item-thumb"> <img src="{{ asset('merchants/images/products/' . $image->image) }}" alt="little picture"></a>
    }
@endforeach

I hope it is helpful for you

Upvotes: 1

Related Questions