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

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

문제

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.

도움이 되었습니까?

해결책

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;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top