itecko
itecko

Reputation: 21

Removing images from the admin panel Laravel \ Backpack

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

Answers (1)

itecko
itecko

Reputation: 21

Iv found the solution.

  1. Add function to the Model

    protected static function booted()
    {
        static::deleted(function ($model) {
            // delete the file
            Storage::disk('public')->delete($model->photo);
        });
    }
    
  2. Add this function to the your NameCrudController.php

     protected function setupDeleteOperation()
     {
         CRUD::field('photo')->type('upload')->withFiles();
     }
    

Upvotes: 1

Related Questions