You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am not sure how this bug was overlooked. But after deleteOldImage() function was moved to the User model, the code does not work as intended. Old files no longer get deleted.
This is the problem code:
protected function deleteOldImage()
{
if ($this->avatar) {
Storage::delete('/public/images/' . $this->avatar);
}
}
The correct code should be this:
protected function deleteOldImage()
{
if (auth()->user()->avatar) {
Storage::delete('/public/images/'.auth()->user()->avatar);
}
}
Since we intend deleting the image that is applicable to the user in session, we should be using auth()->user()->avatar, instead of $this->avatar