0
Good Afternoon. I deployed an APP I am developing in Laravel with PHP 7, in order to generate requests. The application is very simple, has:
- a register and consultation of clients;
- product consultation;
- Order manager (register/query/edit/delete);
Running the project on my machine, all methods (get/post/delete) are running normally, but after deploying the 'DELETE' methods of my "order items" are not working.
The delete functions are not showing up in my log, and I can’t inspect the error either. Has anyone had this problem? Thank you
Delete path.:
Route::delete('painel/pedidos/removeitem', 'Painel\pedidosController@removeItem');
Delete function.:
//****************************************************************************
public static function removeItem(Request $request) {
//****************************************************************************
$id_pedido = $request->id_pedido;
$id_produto = $request->id_produto;
$tamanho = $request->tamanho;
$tot_item = $request->tot_item;
try{
$observacao = "EXCLUINDO NORMALMENTE";
// pega o valor deste registro
$total = PedidosItens::where( 'ID_PEDIDO' , $id_pedido )
->where( 'ID_PRODUTO', $id_produto )
->where( 'TAMANHO' , $tamanho )
->value( 'PRECO_TOTAL' );
// procura pelo item e deleta
$item = PedidosItens::where( 'ID_PEDIDO' , $id_pedido )
->where( 'ID_PRODUTO', $id_produto )
->where( 'TAMANHO' , $tamanho )
->delete();
//se remover SUBTRAI NO TOTAL DO PEDIDO
$total_ped = Pedidos::findOrFail($id_pedido);
$total_ped->TOTAL = ( $total_ped->TOTAL - $total) ;
$total_ped->save();
return response( ['STATUS' => 'OK', "OBSERVACAO" => $observacao , "TOT_ITEM" => $total , "TOTAL_PEDIDO" => $total_ped->TOTAL] );
} catch ( Exception $e ) {
return response( ['STATUS' => 'ERRO', 'ERRO' => $e->getMessage()] );
}
}
Javascript function.:
//****************************************************************************
$("#tabela_itens").on('click', '.btn_exclui_prod' , function() {
//EXCLUI ITEM DO PEDIDO EM MODO GRID
//****************************************************************************
var row = $(this).closest('tr');
var sender = $(this).closest('button');
var id_produto = sender.data('idprod');
var id_pedido = sender.data('idped' );
var tamanho = sender.data('tam' );
var formURL = '/painel/pedidos/removeitem';
if(!modoGrade){
var dados = '{ "id_produto": "' + id_produto + '",' +
'"id_pedido": ' + id_pedido + ',' +
'"tamanho": "' + tamanho + '" }';
}
var jsonobj = JSON.parse(dados);
Pace.track( function(){
$.ajax({ url : formURL,
type : 'DELETE' ,
data : jsonobj ,
dataType : 'json',
success : function(data) {
if (data.STATUS == 'OK') {
row.fadeOut('1000', function() {
row.remove();
});
$("#total_pedido").val( '' );
$("#total_pedido").val("R$ " + data.TOTAL_PEDIDO.toFixed(2) );
console.log(data.STATUS);
}
},
error : function(data) {
console.log(data);
console.log(data.OBSERVACAO);
console.log(data.STATUS);
console.log("ERRO AO DELETAR ITEM");
}
});
});
}); // FIM -> $("#tabela_itens").on('click', '.btn_exclui_prod' , function() {
// FIM DE EXCLUSÃO DE ITENS EM MODO GRID
//****************************************************************************
Welcome to the Stack Overflow in English. A good practice to start a healthy discussion is to do the [tour], if you did, read the [Ask] guide. Start by following these recommendations, especially knowing what types of questions to ask, how to create a minimal example that is complete and verifiable, and even what to do when someone answers you. [Answer]
– Don't Panic
Try putting the following on htaccess: <Limit GET POST PUT DELETE> Allow from all </Limit>
– Diego Schmidt
Unfortunately did not resolve :/
– William Sena
Why complicate, put POST.
– novic