adding a link to edit trashed entries to the Actions column of the section added by TrashOperation #1254
-
I followed the tutorial added at https://backpackforlaravel.com/articles/tutorials/how-to-create-a-trash-deleted-section-in-backpack-crud to add a Trash/Deleted section to my Backpack CRUD. It works well BUT I'd like to be able to edit accounts from this section and idk how to do that. I posted this question before, in #1137, but I was given an answer that was not an answer to my question and the question was then closed. In that question I presented an example of a scenario wherein you might want to do this but then people seemed to confuse my scenario for my question, as if a resolution to the very specific scenario I posted was a resolution to my more general question. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
To add a link to edit trashed entries in the Actions column of the Trash section created using the TrashOperation, you can customize the buttons displayed for trashed items. Here's how you can achieve this:
public function setupTrashOperation()
{
// ... other setup code ...
CRUD::addButton('line', 'edit_trashed', 'view', 'vendor.backpack.crud.buttons.edit_trashed', 'end');
}
@if ($crud->hasAccess('update') && $entry->trashed())
<a href="{{ url($crud->route.'/'.$entry->getKey().'/edit') }}" class="btn btn-sm btn-link">
<i class="la la-edit"></i> Edit
</a>
@endif
public function setupUpdateOperation()
{
// ... other setup code ...
// Allow editing trashed entries
CRUD::setOperationSetting('accessCondition', function($entry) {
return true; // or any condition you want to use
});
}
public function scopeWithTrashed($query)
{
return $query->withTrashed();
} These steps should add an "Edit" button to the Actions column for trashed entries, allowing you to edit them directly from the Trash section. Remember that editing trashed entries might have implications for your application logic, so make sure to handle any potential issues that may arise from editing soft-deleted records. Trash Operation documentation provides more information on customizing the TrashOperation, including how to override buttons and modify operation settings. ℹ️ Please note our AI Bot does not reply to follow-ups, this will be the only AI answer in this thread. If the AI helped you find the answer, please mark it as answered or write details below so it can learn. Then close the conversation. If not, please give more information for when a human reads this. ℹ️ Relevant sources: Laravel backpack overwrite update blade file for just one CRUD |
Beta Was this translation helpful? Give feedback.
-
I believe it is. That's how I'm able to trash accounts at all and then click on the "archived" filter to view archived accounts.
The button appears if I remove the if condition but it only appears when the trashed filter is not selected. ie. with this change I now have two edit buttons for non-trashed users - the edit action that
Doesn't seem to have done anything. |
Beta Was this translation helpful? Give feedback.
-
I came up with a few ways to do this. Method # 1Copy
Then add your new button to this line: $buttons_to_remove = array_filter(Arr::pluck($this->crud->buttons(), 'name'), function ($item) {
return !in_array($item, ['destroy', 'restore', 'trash']);
}); Then create resources/views/vendor/backpack/crud/buttons/edit_trashed.blade.php with the following contents:
Method # 2Copy vendor\backpack\pro\resources\views\buttons\destroy.blade.php to resources\views\vendor\backpack\pro\buttons\destroy.blade.php and then add the button to that:
|
Beta Was this translation helpful? Give feedback.
I came up with a few ways to do this.
Method # 1
Copy
setupTrashFilter()
from backpack/pro/src/Http/Controllers/Operations/Traits/TrashFilter.php to your custom CRUD and add the button:Then add your new button to this line:
Then create resources/views/vendor/backpack/crud/buttons/edit_trashed.blade.php with the following contents: