skip to Main Content

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

Answers


  1. @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
    
    Login or Signup to reply.
  2. 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]

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search