简体   繁体   中英

How to hook into the delete event for a resource in laravel nova?

I have one query, I want to delete the image from the server when particular resource get deleted from Nova.

can anyone suggest me is there any way to override delete method for the resource.

EDIT: How to hook into the delete event for a resource in laravel nova?

Note: I know we can do using observer. but I am looking for another way.

In order to hook into laravel nova's delete resource event, you don't have a builtin way. But the parent model's have a delete method, you can override it and do extra work there

    //app/ParentModel.php

    public function delete() {
       /* add your extra logic for deleted model */

       parent::delete();
    }

you can use boot in your model like this:

public static function boot()
{
    parent::boot();
    self::deleted(function ($model) {
        parent::remove($model, self::$index);
    });
}

我使用了观察者和删除功能新星资源事件并且工作正常

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM