Texas Texas - 2 years ago 90
PHP Question

Laravel doesn't show image

I have this in the view.blade.php


takes the image name from the database

In the same view I have
use HTML;

What I see on the screen is this:

<img src="http://localhost:8000/resources/Folder/Subfolder/Subfolder/Photo/3da0d12d6d8667963392a446262b1773.jpg">

If I replace

<img src="resources/Folder/Subfolder/Subfolder/Photo/{$item->Photo}}" alt="NO PHOTO">

on the screen I see
<img src="http://localhost:8000/resources/Folder/Subfolder/Subfolder/Photo/3da0d12d6d8667963392a446262b1773.jpg">


The pictures exists, I sow it in the folder.
I'm doing something wrong, I just don't know what.
I'm thinking that Laravel wants pictures to be on a specific folder... could this be the cause of the problem? Do you have any ideas?

In controller I have this:

$destinationPath =base_path().'\resources\Folder\Subfolder\Subfolder\Photo';

The picture size is 7.673 bytes.
I tried with other image, it doesn't work either. It's like something prevents all of my browsers to show pictures on localhost
Has anyone encountered this problem before ?
I don' know what else I should try...

Answer Source

In Laravel 5 if you plan to have your images available in public folder, follow this answer:

Create images folder under public folder in Laravel 5.

Afterward what I do, I use URL::to('/') to return base URL, then you can added your images folder location like following example:

<img src="{{ URL::to('/') }}/images/{{ $item->Photo }}" alt="{{ $item->Title }}" />

OR all of it inside the braces

<img src="{{ URL::to('/images/' . $item->Photo) }}" alt="{{ $item->Title }}" />

You should not give write permission to resources folder.

{{ URL::to('/images') }} generate http://localhost/images in local host environment.

and the folder of images location is: your_laravel_project/app/public/images

If you plan to protect your images from public view, so only authenticated user can see the images, then follow this link:

How to protect image from public view in Laravel 5?

Note: URL::to('/') returns base URL and it can be used different ways. Here you can find in depth info about it.

Reference: http://laravel.com/api/5.1/Illuminate/Contracts/Routing/UrlGenerator.html#method_to

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download