问题描述
在我的Laravel项目中,我试图使用刀刃将图像加载到视图中,但它显示为断开的链接.我用萤火虫检查它,并且src指向图像,但什么也没显示.
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.
我的图片位于项目的public/images/users/3/profilePictures/
My image is located in my project's public/images/users/3/profilePictures/
这是我在view.blade.php中的<img>
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 }} {{ $follower->last_name }} Profile" width="50" height="50">
但是我在加载页面时得到了这个信息:
However I get this when I load the page:
当我用萤火虫检查图像时,我看到以下内容:
When I inspect the image with firebug I see this:
那是正确的src,并且该图像确实存在于我的public/images/users/3/profilePictures/目录中
That is the correct src and the image does exist in my public/images/users/3/profilePictures/ directory
有人知道为什么会这样吗?
Anyone know why this is happening?
推荐答案
这可能是由于您所使用的路由不代表基本URL.您应该为资产生成相对于public/
文件夹的URL.使用URL::asset('path/to/asset')
生成URL.
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}") }}
或者如@lukasgeiter所述,您可以简单地使用asset('path/to/asset')
帮助器.
Or as @lukasgeiter mentioned you can simply use asset('path/to/asset')
helper.
这篇关于图像未在视图中显示.拉拉韦尔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!