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?