Laravel Input::get('params.id') is not working when custom http header is set to the post request

StackOverflow https://stackoverflow.com/questions/23674304

Domanda

I've angular for the client side and laravel at the back end. when i try to access the parameters sent to laravel using input::get('params.id') i get null: the client side post request:

 $http.defaults.headers.post = {'X-CSRF-Token':token};

 $http.post('/projectx/public/provider/products/remove/'+PID,{
                           params:{
                               id:$scope.products[index].id,
                               title:$scope.products[index].title,
                               price:$scope.products[index].price
                           }
                       }).success(function(response){
                            if(response.status){
                                UI.simpleNotify('Product removed!','success');
                            }else{
                                console.log(response);
                                UI.simpleNotify('Error removing product!','error');
                            }
                       }).error(function(){
                            UI.connectionError();
                        });

and here is the laravel backend code:

$productId = Input::get('params.productId');

i tried Input::all(); but it returns null.

but when i remove the http custom header ('X-CSRF-Token') on the angular code it works fine.

So what do you think the problem is? Thanks in advance.

È stato utile?

Soluzione

For post and put request, you shouldn't set the default post headers as an object literal.

$http.defaults.headers.post['X-CSRF-Token'] = token;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top