Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$media->delete() doesn't delete files from filesystem #20

Open
AliN11 opened this issue Sep 24, 2019 · 1 comment
Open

$media->delete() doesn't delete files from filesystem #20

AliN11 opened this issue Sep 24, 2019 · 1 comment

Comments

@AliN11
Copy link

AliN11 commented Sep 24, 2019

Hi. As been said in docs:

Media::first()->delete();

Doing so will delete the file from your filesystem, and also remove any association between the media item and your application's models.

By doing this:

foreach ($blog->getMedia('blogs') as $media) {
    $media->delete();
}

It detaches media from the model, doesn't delete files from filesystem.

Laravel version: 6.0
optix/media: 0.2.4
@damarev
Copy link

damarev commented Nov 18, 2019

Hi @AliN11

I have checked the code, I really can't find the implementation of that funcionality.

But, you can create your own Media.php model like this:

use Optix\Media\Models\Media as BaseMedia;

class Media extends BaseMedia
{
    public static function boot()
    {
        parent::boot();
        static::deleted(function ($model){
            $model->filesystem()->deleteDirectory(
                $model->getDirectory()
            );
        });
    }
}

Don't forget to change the config:

return [

    'model' => Your\Path\To\Models\Media::class,

];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants