@xuuto Because the file is not getting stored. You have a syntax mistake use 'storeAs' not 'storeAS'
$request->file('avatar')->storeAs('avatars', $fileName);
i have a mutator which returns current user uploaded image avatar
public function getAvatarAttribute($value)
{
return $value ? asset('storage/' . $value) : asset('/img/defualt-avatar.png');
}
and in my controller ProfileController iam updating user details and avatar image if selected.
public function update(User $user)
{
$attributes = request()->validate([
'username' => ['string', 'required', 'max:255', 'alpha_dash', Rule::unique('users')->ignore($user)],
'name' => ['string', 'required', 'max:255'],
'bio' => ['string'],
'email' => ['string', 'required', 'email', 'max:255', Rule::unique('users')->ignore($user)],
'avatar' => ['file'],
'banner' => ['file'],
'password' => ['string', 'required', 'min:8', 'max:255', 'confirmed'],
]);
if (request('avatar')) {
$fileName = 'profile-' . time() . '.' . $attributes['avatar']->getClientOriginalExtension();
$attributes['avatar'] = request('avatar')->storeAS('avatars', $fileName);
}
$user->update($attributes);
return redirect($user->path());
}
the file uploads to storage app avatars folder and i made php artisan storage:link but is not public storage avatars folder
when i visit this url for the uploaded file
http://localhost:8000/storage/avatars/profile-1605503881.png
it returns 404 page
@xuuto To get the file available in public/storage/avatars your file should upload at storage/app/public/avatars. can you provide the updated code..? to change the uploads to the storage/app/public you should update the env file. Add this
FILESYSTEM_DRIVER="public"
Please or to participate in this conversation.