-1

I am trying to display the profile pictures for users on their posts as part of my website I am creating. However, for some reason it is not displaying the image, in spite of the path being valid.

This is my img tag:

<img class="rounded-full object-cover h-16 w-16" src="{{ url('images/profile_pictures/'.$post->user->id.'.'.$post->user->pfp_file_extension) }}" onerror="this.onerror=null; this.src='images/profile_pictures/default.jpg'"  alt="">

And when I open the image in the browser, I get the url:

http://localhost:8000/images/profile_pictures/

With the error: The requested resource /images/profile_pictures/ was not found on this server.

This is very confusing, because when users visit their profile page, they can see their profile picture just fine, and if it does not exist they see the default.jpg as expected. My img tag for that is very similar:

<img src="{{ url('images/profile_pictures/'.Auth::user()->id.'.'.Auth::user()->pfp_file_extension) }}" onerror="this.onerror=null; this.src='images/profile_pictures/default.jpg'" class="rounded-circle">

And the url it takes me to is the same:

http://localhost:8000/images/profile_pictures/1.jpg

I have tried all the fixes from this post Image not displaying in view. Laravel , but to no avail. I am still hit with the same error.

I was expecting the image to display in the profile picture, however it cannot find the image. It works just fine on the profile page despite using an almost identical src path. Any ideas?

Awc
  • 11
  • 2

1 Answers1

0

If you are saving images in laravel local storage you have to use command php artisan storage:link first and after get image with asset('storage/images/profile_pictures/'.$profile->image)

  • I have already tried this, and it still doesn't work. If this was the error, surely the profile pictures on their profile page would also not display. – Awc Mar 07 '23 at 11:04
  • Can you check laravel.log? – Salikh Gurgenidze Mar 07 '23 at 11:09
  • also please check in your .env file if FILESYSTEM_DISK=local – Salikh Gurgenidze Mar 07 '23 at 11:16
  • the .env is correct, and laravel.log is not showing any relevant error. I just get this error in the PHP terminal: ``` WARN 127.0.0.1:51501 [404]: GET /images/profile_pictures/ - No such file or directory. ``` – Awc Mar 07 '23 at 11:22
  • please add "storage" before and try again: storage/images/profile_pictures – Salikh Gurgenidze Mar 07 '23 at 11:26
  • and make sure u are saving image in storage/app/public/* path – Salikh Gurgenidze Mar 07 '23 at 11:29
  • I have created the storage link with PHP artisan storage:link, and prepended storage to the URL and still have error **WARN 127.0.0.1:51837 [404]: GET /images/profile_pictures/ - No such file or directory.** – Awc Mar 07 '23 at 11:30
  • check storage/app/public/images/profile_pictures/ directory if your image is there – Salikh Gurgenidze Mar 07 '23 at 11:34
  • I am not sure why it is negating the /storage/ part, as it is definitely in the src URL. Even when I manually type in ** http://localhost:8000/storage/images/profile_pictures/1.jpg ** I still get the error WARN 127.0.0.1:52004 [404]: GET /images/profile_pictures/ - No such file or directory. – Awc Mar 07 '23 at 11:36
  • why your ports are always different from each other? try to remove public/storage and regenerate it again – Salikh Gurgenidze Mar 07 '23 at 11:47