简体   繁体   English

如何挂钩laravel nova中资源的删除事件?

[英]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.我有一个查询,当特定资源从 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?编辑:如何挂钩 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.为了挂钩 laravel nova 的删除资源事件,您没有内置方法。 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:您可以像这样在模型中使用 boot:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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