3

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.

Jigar
  • 3,055
  • 1
  • 32
  • 51
  • Did you ever find a solution to this problem? It looks like the accepted answer has nothing to do with Nova. – Citizen Nov 19 '19 at 03:44
  • 1
    its hook which I used to set in model.... if you implement below solution it will work – Jigar Nov 19 '19 at 04:42

3 Answers3

5

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();
    }
Shobi
  • 10,374
  • 6
  • 46
  • 82
0

you can use boot in your model like this:

public static function boot()
{
    parent::boot();
    self::deleted(function ($model) {
        parent::remove($model, self::$index);
    });
}
Alireza Rahmani Khalili
  • 2,727
  • 2
  • 32
  • 33
0

I used Observers and deleted function Nova Resource Events and works fine

Amr Abdalrahman Ahmed
  • 920
  • 1
  • 14
  • 19