Reputation: 3261
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.
Upvotes: 3
Views: 3666
Reputation: 1271
You can also use the afterDelete
method on the resource.
See the HasLifecycleMethods
trait on the Nova Resource
.
/**
* Register a callback to be called after the resource is deleted.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
*/
public static function afterDelete(NovaRequest $request, Model $model)
{
//
}
Upvotes: 0
Reputation: 1010
I used Observers and deleted function Nova Resource Events and works fine
Upvotes: 0
Reputation: 2954
you can use boot in your model like this:
public static function boot()
{
parent::boot();
self::deleted(function ($model) {
parent::remove($model, self::$index);
});
}
Upvotes: 0
Reputation: 11481
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();
}
Upvotes: 5