I would not assume this gives you the correct path
$path = ('avatars/'.$user->username);
where is the file placed?
Storage::disk('public')->delete('avatars/'.$user->username);
Like this perhaps ?
I have a file upload on my website and i am trying to removed the previous picture when i upload a new one.
I have this in my controller
$user = User::find(auth()->user()->id);
$path = ('avatars/'.$user->username);
if(file_exists($path)){
@unlink($path);
}
$user->update([
'avatar' => $this->avatar->store($path, 'wasabi'),
]);
How do i do this please?
If you use storage::disk you need to provide the path relative to the bucket specified by that disk, and not the whole URL..
if(Storage::disk('wasabi')->exists($user->avatar)){
Storage::disk('wasabi')->delete($user->avatar);
}
Please or to participate in this conversation.