当自定义http头被设置为post请求时,Laravel Input::get('params.id')


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

我为客户端设计了角,后端设计了laravel。当我尝试使用input::get('params.id')访问发送给laravel的参数时,我得到null:客户端发布请求:

 $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();
                        });

,这里是laravel后端代码:

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

i tried Input::all();但是它返回null

但是当我在angular代码中删除http自定义头('X-CSRF-Token')时,它可以正常工作。

那么你认为问题是什么?

对于post和put请求,您不应该将默认的post头设置为对象字面值。

$http.defaults.headers.post['X-CSRF-Token'] = token;