0

我正在学习创建一些论坛,但是当我更新照片配置文件时,它无法显示。当我尝试检查元素时,它说:

“加载资源失败:服务器响应状态为 404(未找到)”

这是我的控制器:

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());
}
4

1 回答 1

1

尝试这个:

$hash = auth()->user()->hash;

$filename = $hash . $avatar->getClientOriginalExtension();

$avatar_name = $avatar->storeAs('profile-picture', $filename);

另外,也许您的“个人资料图片”目录中存储了一些带有奇怪文件名的“垃圾”文件

于 2019-11-22T18:28:09.580 回答