1
I’m having trouble effecting a deletion with Laravel 5.3
. By submitting the ajax it simply is not returning me anything.
Man JavaScript
is 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");
}
});
};
Man Controller
thus:
public function delete(\Illuminate\Http\Request $request){
$id = $request->input('id');
return $id;
}
However nothing happens, I tried to use an app to send a POST and check the return, and the error he presented me was due to CSRF_TOKEN but added the first line in my javascript
and did nothing to help.
My sheet of rotas
is 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');