Crud: Unable to access revisions if Soft Delete is enable

Created on 29 Jan 2017  ·  2Comments  ·  Source: Laravel-Backpack/CRUD

Hi,

If soft delete is enable on Model, you can't access to his revisions because function getEntry() Backpack\CRUD\PanelTraits\Read doesn't get trashed elements.

Two options I see:

  1. Disable revision button on trashed element (why do you want to restore a revision if element is deleted‽)
    on view.buttons.revisions edit if with: @if ((isset($entry->trashed()) && !$entry->trashed()) && $crud->hasAccess('revisions') && count($entry->revisionHistory)) and test if trashed on Backpack\CRUD\app\Http\Controllers\CrudFeatures\Revisions function listRevisions($id) to abort action.

  2. Allow getEntry to retrieve trashed element like:

public function getEntry($id)
{
    $entry = $this->model->withTrashed()->findOrFail($id);

    return $entry->withFakes();
}

And disable revisions restoring because you need to restore element before restoring a revision.

Maybe the second option is more relevant, because you could add a restore function like $this->crud->getEntry($id)->restore() simply.

I'm sure you'll find the best solution ! :) _(and maybe add a route for restoring ? ❤️ )_
Best regards
Tof

Bug

Most helpful comment

Hi guys,

My 2 cents on this - I think a pretty good solution already exists:

  • trashed elements should not show up in the CRUD table, it would be confusing to the user to see both real and deleted info (from his perspective);
  • if you need to show the user trashed elements, you can use a filter (see the last example here and also pasted the code at the bottom - it will only show the trashed elements); that makes it more intuitive, I think, he knows those items are all trashed;
  • when that trashed filter is active, you can see only trashed entries and can do everything you can do to an non-trashed entry; so the problem above disappears;

Feel free to comment if you disagree :-)

Cheers!


        $this->crud->addFilter([
          'type' => 'simple',
          'name' => 'trashed',
          'label'=> 'Trashed'
        ],
        false,
        function($values) { // if the filter is active
            $this->crud->query = $this->crud->query->onlyTrashed();
        });

All 2 comments

I'm not convinced that making getEntry($id) returned trashed entries would work (at a cursory glance this would essentially just return deleted items as well as current items to _all_ the views etc which would be bad).

In fact, I could argue that one shouldn't be able to restore to an item that's deleted (even if it is a soft delete) because that just doesn't make sense. If it's not there it's not there and I'm not sure the upstream package may have the same issue.

Hi guys,

My 2 cents on this - I think a pretty good solution already exists:

  • trashed elements should not show up in the CRUD table, it would be confusing to the user to see both real and deleted info (from his perspective);
  • if you need to show the user trashed elements, you can use a filter (see the last example here and also pasted the code at the bottom - it will only show the trashed elements); that makes it more intuitive, I think, he knows those items are all trashed;
  • when that trashed filter is active, you can see only trashed entries and can do everything you can do to an non-trashed entry; so the problem above disappears;

Feel free to comment if you disagree :-)

Cheers!


        $this->crud->addFilter([
          'type' => 'simple',
          'name' => 'trashed',
          'label'=> 'Trashed'
        ],
        false,
        function($values) { // if the filter is active
            $this->crud->query = $this->crud->query->onlyTrashed();
        });
Was this page helpful?
0 / 5 - 0 ratings