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....
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 :-)
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
@simondavies your solution really helped me, I totally forgot that my route checks all PUT/DELETE/GET/POST requests for csrf tokens
Some web servers filter DELETE and PUT requests. This solution is ideal for both the sides. Thanks for the idea :)
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
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.
atlasabzar liked this reply
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community