Support the ongoing development of Laravel.io →
Requests Input
Last updated 1 month ago.
0

That's ok for Laravel. The only possible issue is client side, as jQuery docs say about the type option: "Other HTTP request methods, such as PUT and DELETE, can also be used here, but they are not supported by all browsers".
I think it's only a legacy browser issue, and I don't really know if it would produce a js exception or what.
However, if you want to rest assured, Symfony should handle this for any request:

$.ajax({
    url: route,
    type: 'post',
    data: {_method: 'delete'},
    success: function....
Last updated 1 month ago.
0

thanks for the reply, i was thinking of this the data method as well, as i will probably need to also use the toekn attribute for added protection. Will post once i have an idea how :-)

Last updated 1 month ago.
0

Well i did it this way so i could also pass in the token for csrf':

Within my Modal/Popup:

  <button type="button" class="confirm-btn" data-token="{{ csrf_token() }}">Confirm</button>

Then in the js:

  var token = $(this).data('token');

    $.ajax({
        url:route,
        type: 'post',
        data: {_method: 'delete', _token :token},
        success:function(msg){
  ....

hope this helps others

Last updated 1 month ago.
0

This was extremely helpful! Thanks guys :)

Last updated 1 month ago.
0

@simondavies your solution really helped me, I totally forgot that my route checks all PUT/DELETE/GET/POST requests for csrf tokens

Last updated 1 month ago.
0

helped me too , Thanks guys

Last updated 7 years ago.
0

Some web servers filter DELETE and PUT requests. This solution is ideal for both the sides. Thanks for the idea :)

0

csrf is not required for GET AFAIK

calebcegan said:

@simondavies your solution really helped me, I totally forgot that my route checks all PUT/DELETE/GET/POST requests for csrf tokens

0

Thanks!!! This was very helpful!!

0

Thank you very much. This helped me. I was confused for a few months why AJAX request with DELETE method does not work. It works fine with data: {_method: 'delete'}, now.

Last updated 4 years ago.
0

use tag data in object.. example:

$.post('/deleteRoute',{id:1,action:'delete'});

دریل هیوندای

1

Sign in to participate in this thread!

Full Stack Europe

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.