I am trying to create a bulk feature for my Layout model.
I have the Backpack version "backpack/crud": "4.0.*",
.
I followed the documentation to create a bulk action without interface (Backpack)
First I created the file containing the button and the bulk actions script:
@if ($crud->hasAccess('bulkPrivate') && $crud->get('list.bulkActions'))
<a href="javascript:void(0)" onclick="bulkPrivateDesigns(this)" class="btn btn-sm btn-secondary bulk-button"><i class="fa fa-clone"></i> Hacer privados</a>
@endif
@push('after_scripts')
<script>
if (typeof bulkPrivateDesigns != 'function') {
function bulkPrivateDesigns(button) {
if (typeof crud.checkedItems === 'undefined' || crud.checkedItems.length == 0) {
new Noty({
type: "warning",
text: "<strong>{{ trans('backpack::crud.bulk_no_entries_selected_title') }}</strong><br>{{ trans('backpack::crud.bulk_no_entries_selected_message') }}"
}).show();
return;
}
var message = "Estás a punto de hacer privados :number diseños, ¿estás seguro?";
message = message.replace(":number", crud.checkedItems.length);
// show confirm message
swal({
title: "{{ trans('backpack::base.warning') }}",
text: message,
icon: "warning",
buttons: {
cancel: {
text: "{{ trans('backpack::crud.cancel') }}",
value: null,
visible: true,
className: "bg-secondary",
closeModal: true,
},
delete: {
text: "Hacer privados",
value: true,
visible: true,
className: "bg-primary",
}
},
}).then((value) => {
if (value) {
var ajax_calls = [];
var clone_route = "{{ url($crud->route) }}/bulk-private";
// submit an AJAX delete call
$.ajax({
url: clone_route,
type: 'POST',
data: {
entries: crud.checkedItems
},
success: function(result) {
// Show an alert with the result
new Noty({
type: "success",
text: "<strong>Hacer privado masivo</strong><br>" + crud.checkedItems.length + " diseños han sido puesto como privados"
}).show();
crud.checkedItems = [];
crud.table.ajax.reload();
},
error: function(result) {
console.log(result);
// Show an alert with the result
new Noty({
type: "danger",
text: "<strong>Hacer privado masivo</strong><br>Uno o más diseños no han podido hacerse privados"
}).show();
}
});
}
});
}
}
</script>
@endpush
Then I modified the file DesignCrudController.php
:
class DesignCrudController extends CrudController
{
public function bulkPrivate()
{
$this->crud->hasAccessOrFail('create');
$entries = $this->crud->getRequest()->input('entries');
Design::whereIn('id', $entries)->update(['private' => 1]);
return $entries;
}
protected function setupBulkPrivateRoutes($segment, $routeName, $controller)
{
Route::post($segment . '/bulk-private', [
'as' => $routeName . '.bulkPrivate',
'uses' => $controller . '@bulkPrivate',
'operation' => 'bulkPrivate',
]);
}
protected function setupBulkPrivateDefaults()
{
$this->crud->allowAccess('bulkPrivate');
$this->crud->operation('list', function () {
$this->crud->enableBulkActions();
$this->crud->addButtonFromView('top', 'bulkPrivateDesigns', 'bulkPrivateDesigns', 'beginning');
});
}
}
And that's all, I would expect it to AJAX
work correctly, but when executing I get this error:
message: "No hint path defined for [errors]. (View: /Users/Yo/MyProject/resources/views/errors/403.blade.php)"
I did some research and it seems like it was an issue where it doesn't find Laravel's error views, but they do exist:
I already tried a php artisan optimize
and composer dump-autoload
. I simulated errors to see that the error views worked correctly and it did, all good. The rest of the views in backpack work fine, but this is the first implementation of the project for mass actions.
I have been dealing with this error for a couple of days, which is the first time I have encountered it, in the tutorial there is nothing of this type of error and I have not been able to solve it.