php - 如何在刀片上显示保存在存储文件夹中的图像
问题描述
我想在刀片视图中显示保存在存储目录中的图像。我成功地将文件存储到 storage/app/public 文件夹,就像 ProfilesController 文件一样:
`if(request('image')) {
$imagePath = request('image')->store('profile', 'public');
$image = Image::make(public_path("storage/{$imagePath}"))->fit(1000, 1000);
$image->save();
}
auth()->user()->profile->update(array_merge(
$data,
['image' => $imagePath]
));`
现在我想在我的 index.blade.php 文件中检索图像。这是如何做到的:
<img src="/storage/{{$user->profile->image}}" alt="">
laravel 文档说在我的终端中使用存储链接我这样做了
php artisan storage:link
我尝试了所有这些,但是视图中没有图像加载!
我在做什么错以及如何解决!
解决方案
您应该在用户配置文件模型中使用访问器,即:-
public function getImageAttribute($image) { return asset('storage'.$image); }
推荐阅读
- json - JSON:Spring Boot 条件验证
- amazon-web-services - 是否可以从订阅中提取 Cloudwatch 日志的内容
- java - 由 defaultValue 引起的将 int 从一个活动传递到另一个活动的问题
- selenium - .net 3.5 视觉工作室的硒
- linux - 使用内核的默认操作来处理信号 SIGABRT 有时不会终止进程
- java - PMD - Java 8 - 得墨忒耳法则
- node.js - 如何修复此身份验证控制器并使其在 Node js (Express) 中正常工作?
- vue.js - Vue可拖动:输入字段
- e-commerce - 为市场商店创建第一个管理员角色的理想方式
- bash - Shell 脚本:如何获取所有使用文件系统/目录的进程 ID