Reputation: 21
I encountered a problem with deleting photos from the admin panel. When I click the delete button on a photo, the photo is deleted only from the admin panel and the database, I remain in the public folder, how can I solve this task?
Upvotes: 1
Views: 18
Reputation: 21
Iv found the solution.
Add function to the Model
protected static function booted()
{
static::deleted(function ($model) {
// delete the file
Storage::disk('public')->delete($model->photo);
});
}
Add this function to the your NameCrudController.php
protected function setupDeleteOperation()
{
CRUD::field('photo')->type('upload')->withFiles();
}
Upvotes: 1