Kamil Kiełczewski Kamil Kiełczewski - 1 month ago 15
PHP Question

Laravel blade img not loading from different links

I have page-template.blade.php file with image:

<img src="./images/picture.png">

And i have three views which extends page-template:

When i go to site from http://exaple.com/ and http://exaple.com/login i see picture.png (browser read it from http://exaple.com/images/picture.png ). But when I go to site from http://exaple.com/change-password/token then I don't see picutre (because browser star read it from: http://exaple.com/change-password/images/picture.png which doesn't exist)



It is not because of Blade templates. When you start path from dot src="./images/picture.png", web-browser is trying to find PNG file relatively to directory of current HTML file in URL.

If you have an image <img src="./images/picture.png"> in file available by URL: http://example.com/dir1/dir2/dir3/file, browser will try to fetch file from http://example.com/dir1/dir2/dir3/images/picture.png

As @alexey-mezenin said, you can use asset() helper or use absolute path <img src="/images/picture.png"> if you sure, that your site will never be available in subdirectory.