Skip to content

CODE BUG: Old image files are not deleted after deleteOldImage file was moved to the User Model. #9

@elnobun

Description

@elnobun

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

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions