Im using ajax to make a delete request, but for some reason, after making the first request to the right route, it makes another request to the current route. I only immplement the submission to the route of /products/id and not to the current route that is /galleries/id
My ajax is :
//Deleting records
$(".deleteProduct").click(function(){
var id = $(this).data("id");
var token = $(this).data("token");
$.ajax(
{
url: "/products/"+id,
type: 'DELETE',
dataType: "JSON",
data: {
"id": id,
"_method": 'DELETE',
"_token": '{{Session::token()}}',
},
success: function ()
{
console.log("it Work");
$('#delete').hide();
}
});
console.log("It failed");
$('#delete').show();
});
delete controller:
public function destroy($id)
{
$product = PhotoGallery::find($id);
$product->delete();
Session::flash('success', 'The product was successfull deleted');
return back();
}
route:
Route::delete('products/{id}', 'PhotoGalleryController@destroy');
Note: The product im deleting in ajax is a list of products that are inside of a form
<form method="POST" id="myform" action="/galleries/{{$gallery->id}}" class="" role="form" enctype="multipart/form-data" >
{{ method_field('PUT') }}
{{csrf_field()}}