I have the following form:
<form action="#" method="post" role="form" class='forms' id="frmDeleteRoundCategory">
{{ csrf_field() }}
<input type="hidden" name="id_round" id='id_round' />
<input type="hidden" name="id_category" id='id_category' />
<p class="alert alert-danger">
¿ Eliminar la ronda <strong class="round"></strong> de la categoría <strong class="category"></strong>?
</p>
<div class="button-group modal-footer" >
<button type="button" data-dismiss="modal" aria-label="Close" class="btn btn-default">
<i class="fa fa-close" aria-hidden="true"></i> Cerrar
</button>
<button type="submit" class=" btn btn-danger">
<i class="fa fa-trash" aria-hidden="true"></i> Eliminar
</button>
</div>
</form>
The form data is sent by JS
//DELETE
$("#frmDeleteRoundCategory").submit(function (e) {
e.preventDefault();
axios.delete("/round_category/" + $("#frmDeleteRoundCategory #id_round").val(), $(this).serialize())
.then(function (response) {
toastr.success(response.data);
});
});
I have the route defined as:
Route::resource('round_category', 'RoundCategoryController');
And I have the destroy method in the controller:
public function destroy(Request $r, $id_round) {
dd($r->all());
}
When sending the data, the dd() shows me an empty array [].
I tried doing console.log($(this).serialize()); and it shows me the data well:
_token=kvvSzXwBABQFjami6EHXxYmtXQtxe7AgKYvpu24y&id_round=5&id_category=13
I have 5 other ABMs with the axios.delete method copied as is and they work perfectly. I only have a problem with this Delete, where axios is not sending the data or there is something that I am not seeing. Because following the steps I have everything defined:
1) I have the route defined Route:resource... 2) I capture the event with js and send the data with axios.delete 3) The call reaches the destroy method, but without the data.
When you use you
axios.delete
have to useparams
instead ofdata
,data
it is only available forPUT
,POST
andPATCH
.With that, your code would look like this: