maaz's avatar
Level 2

How to show three images instead of more than three.

Hello everyone. I am letting users upload multiple images but I want to show only three images in my view. my view

       <div class="business-gallery">
                        <div class="gallery">
                            {{-- {{dd($business->image)}} --}}
                            {{-- @json($business->image) --}}
                            @foreach(explode(',', $business->image) as $path)
                            <a href="{{ asset('storage/'.$path) }}" data-caption="Image caption">
                                <img src="{{ asset('storage/'.$path) }}" alt="{{ asset('storage/'.$path) }}" />
                            </a>
                            @endforeach
                        </div>
                    </div>

Note: Ignore Comments in my code :) thankyou

0 likes
2 replies
MichalOravec's avatar
Level 75
<div class="business-gallery">
    <div class="gallery">
        @foreach(explode(',', $business->image) as $path)
            @break ($loop->index == 3)

            <a href="{{ $path = asset("storage/{$path}") }}" data-caption="Image caption">
                <img src="{{ $path }}" alt="{{ $path }}">
            </a>
        @endforeach
    </div>
</div>

Docs: https://laravel.com/docs/7.x/blade#loops (look for end the loop or skip the current iteration) and https://laravel.com/docs/7.x/blade#the-loop-variable

Please or to participate in this conversation.