PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 8, 2022

[FIXED] Image not displaying in view. Laravel

 March 08, 2022     blade, laravel     No comments   

Issue

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?


Solution

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.



Answered By - Mohebifar
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing