Laravel backpack csrf problem while deleting entries

Viewed 145

I have installed laravel backpack, followed the official tutorial: https://backpackforlaravel.com/docs/4.1/crud-tutorial and created Tag model with admin crud. Everything but delete works fine. While clicking the delete button in admin panel I am getting an error There's been an error. Your item might not have been deleted.

In devtools I saw that I am getting a 419 error and the message says CSRF token mismatch.. What may cause the problem and how can I fix it?

Information in devtools Console:

enter image description here

Information in devtools Network:

enter image description here

1 Answers

In order to fix this I have copied delete.blade.php file from vendor/backpack/crud/src/resources/views/crud/buttons/delete.blade.php

to

resources/views/vendor/backpack/crud/buttons/delete.blade.php

Then I added x-csrf-token header to ajax request in 29th line of file

headers: {
    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},

Now the request is sent with x-csrf-token header and delete is successful

Related