2

I'm trying to display the image that is stored in my public folder. The path to my image is being displayed when i just use {{$post-> image}} but i cant get the image to be displayed when i run the following command.

@foreach($posts -> $post)
      <tr>
                <td> <img src="{{ asset($post->image) }}" alt=""></td>
                <td> {{ $post-> title }} </td>
      </tr>
@endforeach

chrome screenshot folder screenshot

1 Answers1

1

Base on your picture the only path you're calling is public/posts/picture.jpg but also based on your picture you need to call public/storage/posts/picture.jpg so you need

{{asset('storage/posts/picture.jpg')}}
Jovs
  • 852
  • 7
  • 23
  • it is working fine now but how do you make the picture source link dynamic? like i used {{ $post->image }} – Anamol Shrestha Jun 27 '19 at 02:57
  • what do you mean? well just add the needed path before you put it on database or input it normally in your blade. if this answer your question please accept it as the answer. Thank you! – Jovs Jun 27 '19 at 03:12
  • this code helps only for a single image, how do I set the path dynamically? {{asset('storage/$post->image')}} is not working. – Anamol Shrestha Jun 27 '19 at 03:33
  • 1
    you need to use `@foreach` in blade are you getting the data in your controller and database? – Jovs Jun 27 '19 at 03:36
  • yes i'm using array , $post is my value. what should be my code? {{ asset('storage/here'}} – Anamol Shrestha Jun 27 '19 at 03:39
  • 1
    please update your question with the code of your full foreach in blade if you're already using one. If not use `@foreach($arrayorcollection as $data) //html and data value here @endforeach` – Jovs Jun 27 '19 at 03:42
  • if you do foreach you're still getting one image? – Jovs Jun 27 '19 at 05:19
  • i just copy pasted your code for and replaced picture with the filename, i tried doing {{asset('storage/posts/$post->image')}} but its not working. – Anamol Shrestha Jun 27 '19 at 12:08