【发布时间】:2020-10-03 19:40:34
【问题描述】:
我正在学习 laravel,但现在图像有问题, 我希望它保存在 storage/app/public/avatar 中以便我可以显示它,但它一直保存在 storage/app/avatar 中
我在 .env 中写了这个
FILESYSTEM_DRIVER=public
然后我生成存储链接
php artisan storage:link
但还是一样,每次我上传照片时,它都会将其保存在存储/应用程序/头像中
谁能帮帮我?
在文件系统.php中
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
这里:
$attributes['avatar'] = request('avatar')->store('public/avatars');
在 USer.php 中
public function getAvatarAttribute($value)
{
return asset($value);
}
当我使用随机头像链接时,此方法可以正常工作, 但现在它什么也没显示,我检查了我的数据库,链接在那里,而且是正确的
public function getAvatarAttribute($value)
{
asset('storage/avatars/'.$image->name);
}
$attributes['avatar'] = request('avatar')->store('public/avatars');
在控制器中,更新方法:
$user->update($attributes);
$user->password = Hash::make($user['password']);
$user->save();
return redirect($user->path());
在show.blade中
<img
src= "{{ $user->avatar }}"
alt=""
class="rounded-full mr-4 absolute"
style="width: 150px; left: calc(50% - 75px); top: 300px"
>
但是 src 变成了“(未知)”
【问题讨论】:
-
嗨,阿里,你能把你的代码显示在你试图保存图像的地方吗?
-
你觉得我应该写 store('public/avatars') 吗?
-
是的!可能利用
$image->move($filepath,$filename); -
好的,我把它更新到store('public/avatars'),它的工作,但现在我没有在网站上显示图像,我会更新代码
-
你还需要保存图片的url。或
assert('/avatars/filename.file-ext')