@endf" /> @endf" /> @endf"/>

How Can I Display Single Image From Array Of Images

67 Views Asked by At

Here My Codes That Fetch All Images

@foreach (explode('|', $product->images) as $image) <img style="width:100%" src="/storage/image/{{$image}}"> @endforeach

Only I want To Display the first image from this array How Can i Do That

2

There are 2 best solutions below

2
Nikunj Gadhiya On

So, just do it in the blade like this

@if (!empty($product->images))
    @php
        $images = explode('|', $product->images);
    @endphp
    @if (count($images) > 0)
        <img style="width:100%" src="/storage/image/{{$images[0]}}">
    @endif
@endif
0
Saheed Lasisi On

I hope this helps.

So, if you're passing the array from your controller to view/blade page then you should just do.

img src="/storage/image/{{$image[0]}}"

E.g $images = [ 'image1.jpg', 'image2.jpg', 'image3.png', 'etc.jpg' ]

Then you pass $images

:Then call $images[1]