3

I was working on an admin panel using backpack for Laravel. When I want to delete some item by hitting the delete button, I get a Not Deleted error - see screenshots.

enter image description here

enter image description here

It looks like the 403 and 405 errors that can occur when the CRUD::resource() or Route::resource method are used but the server (apache in my case) does not allow them on dynamic resources - whatever that means in detail ...

Is there a way to enable these methods on Apache?

I got it working, but I would like to use the default HTTP methods.

Quick Fix

I was able to fix this problem by duplicating and modifying the list.blade.php CRUD view of backpack.

  1. Duplicate the view vendor/backpack/crud/src/resources/views/list.blade.php and move it to resources/views/vendor/backpack/crud/list.blade.php

  2. Modify the AJAX request defined on line 271.

     if (confirm("{{ trans('backpack::crud.delete_confirm') }}") == true) {
          $.ajax({
              url: delete_url,
              type: 'POST', // change from DELETE to POST
              data: { // "spoof" the HTTP verb "DELETE"
                "_method": "DELETE"
              },
    
halfer
  • 19,824
  • 17
  • 99
  • 186
Thomas Venturini
  • 3,500
  • 4
  • 34
  • 43

2 Answers2

1

laravel/framework: 5.8.2 backpack/crud: 3.6

vendor/backpack/crud/src/resources/views/buttons/delete.blade.php replace this code: type: 'DELETE',

with this lines:

type: 'POST',
data: {
      "_method": "DELETE"
},  
Himani Bhatt
  • 41
  • 1
  • 7
-1

you should check Access in you controller

$this->crud->allowAccess(['delete']);

i think you no necessary so complex like this. when you install backpack,you shoudld run like

php artisan vendor:publish --provider="Backpack\Base\BaseServiceProvider" #publishes configs, langs, views and AdminLTE files

it will auto copy file to right place

yang
  • 1