[英]My profile picture doesn't show in Laravel 6
I'm learning to create some forum, but when I update a photo profile, it can't show.我正在学习创建一些论坛,但是当我更新照片配置文件时,它无法显示。 When I try to inspect element it says:
当我尝试检查元素时,它说:
"Failed to load resource: the server responded with a status of 404 (Not Found)"
“加载资源失败:服务器响应状态为 404(未找到)”
This is my Controller:这是我的 Controller:
public function update()
{
$avatar = request()->file('avatar');
$avatar_validate = 'image|mimes:jpeg,png,jpg,svg|max:2048';
request()->validate([
'username' => 'required|alpha_num|min:6|max:20|unique:users,username,' . auth()->id(),
'name' => 'string|required',
'avatar' => $avatar ? $avatar_validate : "",
]);
$hash = auth()->user()->hash;
$avatar_name = $avatar->storeAs('profile-picture', "{$hash}.{$avatar->extension()}");
auth()->user()->update([
'username' => request('username'),
'name' => request('name'),
'avatar' => $avatar_name,
]);
return redirect()->route('users.show', auth()->user()->usernameOrHash());
}
Try this:尝试这个:
$hash = auth()->user()->hash;
$filename = $hash . $avatar->getClientOriginalExtension();
$avatar_name = $avatar->storeAs('profile-picture', $filename);
Also maybe you have some "trash" files stored with a weird filename in your "profile-picture" directory另外,也许您的“个人资料图片”目录中存储了一些带有奇怪文件名的“垃圾”文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.