laravel: looping images folder with index value

Viewed 604

enter image description herei am trying to show an image from the images folder however the image is not showing although i am able to see it in an array if i die and dump the "$image". The images are located in "public/images" folder

blade file

<div class="gallery"> 
            @foreach($posts as $post)
           <div class="round-post">
               @foreach ($post->images as $image)
               <a href="/images/{{$image[0]}}"  data-lightbox='lo'> <img src="/images/{{$image[0]}}"  data-lightbox='lo'class = "img-posts" alt=""> </a>
             
                 ........

               @endforeach
            
            @endforeach
        </div>[![enter image description here][1]][1]

when i <img src="/images/ <?php dd($image[0]); i get enter image description here

1 Answers

this bunch of code get your images that exist in your images folder:

public function index(){

    $images = \File::allFiles(public_path('images'));

    return View('pages.form')->with(array('images'=>$images));

}

this will show the images in your blade.

            <ul>
            @foreach ($images as $image)
                 <li style="width:80px;display:inline-block;margin:5px 0px">
                     <input type="checkbox" name="images[]" value="{{$image->getFilename()}}"/>
                     <img src="{{ asset('images/' . $image->getFilename()) }}" width="50" height="50">
                 </li>
            @endforeach
            </ul>

for more information you can read this article.

Good luck my friend!

Related