Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

laravel_beginner's avatar

I have a problem with display image in laravel with html

I am trying to show image with html and I am sure I have right the src, even when I am with cursor on it the image will pop up and I don't have problem with wifi connection, but still it will just show the alt.

<img  src="public/images/1663946644-e.jpg" alt="Problem with loading image">

Anybody knows why is that?

0 likes
15 replies
Snapey's avatar

your url is relative to the current url, so if your url is post/5 then the image will be looked for at post/public/images....

Your src url needs to start with a / to make it relative to the root folder

But something is off with your hosting, public should not appear in any urls

laravel_beginner's avatar

If I add / before public like that: <img src="/public/images/1663946644-e.jpg" alt="Problem with loading image"> Then nothing change. If I will delete the public: <img src="/images/1663946644-e.jpg" alt="Problem with loading image"> It will return with message Cannot resolve file '1663946644-e.jpg' But if I let it as it is let cursor on the src, then the image will show up on the screen, so I think the problem shouldn't be in src.

Sinnbeck's avatar

@laravel_beginner All of your urls have storage/app/public in them? Or did you misunderstand the question? I am talking about the url in your browser, not the folders on the computer

What url do you visit your site on? (you can anonymize the domain if needed)

laravel_beginner's avatar

@Sinnbeck No sorry I misunderstand your question, you asked if I have some other public so I looked and in direction /storage/app/public found another folder named public, but the images are stored in normal public public/images

laravel_beginner's avatar

@Sinnbeck Yes you are right it works, but I don't get it is highlighted and writes Cannot resolve directory 'images'. That's also why I didn't tried it on the website, when I saw this in phpstorm

zoidq's avatar

If your development web address is, for example: http://localhost:8000/

Can you access: http://localhost:8000/public/images/1663946644-e.jpg ? (replace localhost:8000 with your address).

If not, the file most likely does not exist on the filesystem at that address.

If so, maybe you need to add a forward slash / before your img address so it looks like:

<img  src="/public/images/1663946644-e.jpg" alt="Problem with loading image">

Notice the / before public.

Please or to participate in this conversation.