I'm having trouble effecting a deletion with Laravel 5.3
. By submitting the ajax it simply is not returning anything to me.
My JavaScript
looks like this:
$.ajaxSetup({ headers: { 'csrftoken' : '{{ csrf_token() }}' } });
function excluir(id){
swal({
title: "Tem certeza?",
text: "Você não será capaz de recuperar este item!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Sim, excluir!",
cancelButtonText: "Não, voltar!",
closeOnConfirm: false,
closeOnCancel: false
}, function(isConfirm){
if (isConfirm) {
var url = location.href; //pega endereço que esta no navegador
url = url.split("/"); //quebra o endeço de acordo com a / (barra)
jQuery.ajax({
type: "POST",
url: url[2] + "/clientes/delete",
data: id,
success: function( data )
{
alert( data );
swal("Excluido!", "Seu item foi excluido com sucesso. "+id, "success");
}
});
} else {
swal("Cancelado", "Seu item está seguro", "error");
}
});
};
My Controller
like this:
public function delete(\Illuminate\Http\Request $request){
$id = $request->input('id');
return $id;
}
But nothing happens, I tried to use an app to send a POST and check the return, and the error that he presented me was due to CSRF_TOKEN but I added the first line in my javascript
and it did not work.
My rotas
sheet looks like this:
Route::singularResourceParameters();
Route::auth();
// ROTAS DE DELEÇÃO
Route::post('/clientes/delete', [
'uses' => 'ClienteController@delete',
'as' => 'produtos.delete'
]);
// FIM DE ROTAS DE DELEÇÃO
Route::get('/', function () {
return view('welcome');
});
Route::resource('clientes', 'ClienteController');