Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image not displaying in view. Laravel

Tags:

laravel

blade

In my Laravel project I'm trying to load an image into my view using blade but it displays as a broken link. I inspect it with firebug and the src is pointing to the image but nothing is displaying.

My image is located in my project's public/images/users/3/profilePictures/

Here is my <img> in the view.blade.php

<img class="com-profile-picture" src="images/users/{{ $follower->id }}/profilePictures/50thumb-{{ $follower->profilePicture->url }}" alt="{{ $follower->first_name }}&nbsp;{{ $follower->last_name }} Profile" width="50" height="50">

However I get this when I load the page:

enter image description here

When I inspect the image with firebug I see this:

enter image description here

That is the correct src and the image does exist in my public/images/users/3/profilePictures/ directory

Anyone know why this is happening?

like image 251
xslibx Avatar asked Jan 18 '15 05:01

xslibx


3 Answers

This may be caused you are in a route which does not represent the base URL. You should generate the URL for your assets relative to the public/ folder. Use URL::asset('path/to/asset') to generate the URL.

{{ URL::asset("images/users/{$follower->id}/profilePictures/50thumb-{$follower->profilePicture->url}") }}

Or as @lukasgeiter mentioned you can simply use asset('path/to/asset') helper.

like image 113
Mohebifar Avatar answered Sep 19 '22 18:09

Mohebifar


You can try with the

php artisan storage:link

else you can use this

A simple fix for the issue (linked broken error) in .env file

APP_URL=http://localhost

this replace with the

APP_URL=http://localhost:8000

then the issue will be fixed.

like image 43
Thilina Dharmasena Avatar answered Sep 18 '22 18:09

Thilina Dharmasena


delete already generated symlink and then run this command

php artisan storage:link
like image 42
Ali Akbar Afridi Avatar answered Sep 18 '22 18:09

Ali Akbar Afridi