skip to Main Content

How can I check the current record is trashed in laravel backpack list operation?

I am trying to hide ‘edit’ button/action if the record is trashed/soft deleted in backpack laravel

 if($this->crud->getCurrentEntry()->{is_trashed} === true) {
    CRUD::denyAccess(['edit']);
  }

Laravel:8.x
Backpack:5.x

2

Answers


  1. You can check if the current record is trashed or not by calling the trashed() method on the Eloquent model object.

    In your Backpack CRUD controller, you can conditionally append the actions column based on the trashed state of the record.

    sth like this:

    $this->crud->addColumn([
       'name' => 'actions',
       'type' => 'closure',
       'function' => function($entry) {
           if($entry->trashed()) {
               // return the action buttons you want to show for trashed records
           } else {
               // return the action buttons for non-trashed records
           }
       }
    ]);
    
    Login or Signup to reply.
  2. You can try override the edit button and change the first line like this

    @if ($crud->hasAccess('update', $entry) && !$entry->trashed())
    

    Cheers.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search