在我的Laravel项目中,我正在尝试使用刀片将图像加载到我的视图中,但它显示为断开的链接.我用firebug检查它,src指向图像但没有显示.
我的图片位于我项目的public/images/users/3/profilePictures /
这是我<img>在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">
Run Code Online (Sandbox Code Playgroud)
但是,当我加载页面时,我得到了这个:

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

这是正确的src,图像确实存在于我的public/images/users/3/profilePictures /目录中
任何人都知道为什么会这样吗?
Thi*_*ena 12
你可以试试
php artisan storage:link
Run Code Online (Sandbox Code Playgroud)
否则你可以使用这个
.env文件中问题(链接损坏错误)的简单修复
APP_URL=http://localhost
Run Code Online (Sandbox Code Playgroud)
这替换为
APP_URL=http://localhost:8000
Run Code Online (Sandbox Code Playgroud)
那么问题将得到解决。
这可能会导致您处于不代表基本URL的路径中.您应该为您的资产生成相对于该public/文件夹的URL .使用URL::asset('path/to/asset')生成的URL.
{{ URL::asset("images/users/{$follower->id}/profilePictures/50thumb-{$follower->profilePicture->url}") }}
Run Code Online (Sandbox Code Playgroud)
或者@lukasgeiter提到你可以简单地使用asset('path/to/asset')帮助器.
| 归档时间: |
|
| 查看次数: |
14999 次 |
| 最近记录: |