Monday, March 6, 2017

laravel 5.4 backpack can't delete item - 403 Forbidden

I was working on an admin panel using backpack for laravel. When I wan't 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 ressources - 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. Go ahead and modify the ajax request defined on line 271.

     if (confirm("") == true) {
          $.ajax({
              url: delete_url,
              type: 'POST', // change from DELETE to POST
              data: { // "spoof" the HTTP verb "DELETE"
                "_method": "DELETE"
              },
    
    


via Thomas Venturini

Advertisement