图像未在视图中显示。 Laravel

时间:2015-01-18 05:29:23

标签: laravel blade

在我的Laravel项目中,我正在尝试使用刀片将图像加载到我的视图中,但它显示为断开的链接。我用firebug检查它,src指向图像但没有显示任何内容。

我的图片位于我的项目的public / images / users / 3 / profilePictures /

以下是view.blade.php中的<img>

<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">

但是,当我加载页面时,我得到了这个:

enter image description here

当我用萤火虫检查图像时,我看到了:

enter image description here

这是正确的src,图像确实存在于我的public / images / users / 3 / profilePictures /目录中

任何人都知道为什么会这样吗?

3 个答案:

答案 0 :(得分:7)

这可能会导致您处于不代表基本URL的路径中。您应该为相对于public/文件夹的资产生成URL。使用URL::asset('path/to/asset')生成网址。

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

或者@lukasgeiter提到你可以简单地使用asset('path/to/asset')助手。

答案 1 :(得分:0)

您可以尝试

php artisan storage:link

否则您可以使用此

此问题的简单解决方法(链接的错误) 在.env文件

APP_URL=http://localhost

将此替换为

APP_URL=http://localhost:8000

然后将解决此问题。

答案 2 :(得分:0)

删除已经生成的符号链接,然后运行这个命令

php artisan storage:link
相关问题