So resources URL's only work from the route. So my prefixing your image with a / you will make sure it always starts looking at the root of your site. In this case of Laravel it's the public directory.
<img src="/images/my-image.png" alt="">
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
This is a very basic question. Why does the route/URL affects the location of an image?
| ------------------------------------ 1 - Case ONE: -----------------------------------------|
This works fine image can be accessed...
Image Location:
public > images > my-image.png
Route:
Route::get('apps', function () {
return view('apps');
});
View:
resources > views > apps.blade.php
<img src="images/my-image.png" alt="">
| ------------------------------------ 2 - Case TWO: -----------------------------------------|
This does NOT work, image CANNOT be accessed any more...
Image Location:
public > images > my-image.png
Route:
Route::get('apps/appName', function () {
return view('appName');
});
View:
resources > views > appName.blade.php
<img src="images/my-image.png" alt="">
In theory the only difference between the two cases is the URL. Can someone explain how does the URL affects the location of the image? I thought that the routs was just that a URL not the folder structure.
My point is that if in both cases the page appName.blade.php is in the same location and pointing to the same folder structure where the image resides why the second case doesn't work. Perhaps I don't understand how URLs work in general, sorry.
So resources URL's only work from the route. So my prefixing your image with a / you will make sure it always starts looking at the root of your site. In this case of Laravel it's the public directory.
<img src="/images/my-image.png" alt="">
Please or to participate in this conversation.