1

I have some images stored in the following paths:

/storage/app/public/uploads/users/2/avatar/0d8c18a52732bc9b0068102338fbf29b.jpeg

or

/storage/app/public/uploads/users/3/avatar/0d123dfd32bc9b0068102338fbf29b.jpeg

I had this paths stored in the users table. How can I display it in my view.blade.php file ? I tried smth like this:

<img src="{{ url('/') }}{{ $user->avatar }}" alt="avatar">

But the image is not found on this path. Any idea ?

Attila Naghi
  • 2,535
  • 6
  • 37
  • 59
  • The image has to be in your "public" folder ... the browser do not see anything thats not in that public by default configuration. look here --> http://tutsnare.com/upload-files-in-laravel/ – Simon Müller Feb 05 '17 at 14:54
  • I saw a lot if examples , there are storing files in the storage folder: http://stackoverflow.com/questions/39748377/laravel-access-images-outside-public-folder or http://stackoverflow.com/questions/30191330/laravel-5-how-to-access-image-uploaded-in-storage-within-view – Attila Naghi Feb 05 '17 at 14:55
  • take a look at this https://laravel.com/docs/5.3/filesystem#file-urls – Afif Zafri Feb 05 '17 at 14:57

1 Answers1

0

You need to use the syntax as

<img src='{{ asset("path-to-your-file") }}' alt='avatar'>

instead

<img src="{{ url('/') }}{{ $user->avatar }}" alt="avatar">

asset() points to public folder. path-to-your-file means the rest of the path

Edit

Additionally I have previously posted a similar answer. Please take a look at it too.

Community
  • 1
  • 1
Gayan
  • 3,614
  • 1
  • 27
  • 34