Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将参数传递到要编辑的Laravel的角度_Javascript_Php_Angularjs_Laravel - Fatal编程技术网

Javascript 将参数传递到要编辑的Laravel的角度

Javascript 将参数传递到要编辑的Laravel的角度,javascript,php,angularjs,laravel,Javascript,Php,Angularjs,Laravel,我使用的是Laravel5.1,请求如何通过api调用接受angular传递的id?这是我的密码 angular.module('MyApp') .factory('Account', function($http){ return { getProductToEdit: function(pid){ //console.log(pid) ----> return 16 return $http.get

我使用的是Laravel5.1,请求如何通过api调用接受angular传递的
id
?这是我的密码

angular.module('MyApp')
    .factory('Account', function($http){
        return {
getProductToEdit: function(pid){
                //console.log(pid) ----> return 16
                return $http.get('/api/productedit',pid);
            }
    }   
    });
我的支持功能:

public function updateProductAPI(Request $request)
    {
         $prodId = $request->all(); ---> return []
         // $request->input('pid'); ---> Object {}

         return response()->json($prodId);
    }

谢谢

传递到
$http.get
函数的第二个对象是配置对象。您需要在此对象上设置params属性,以便随请求发送数据

$http.get('url', { params : { pid : pid } });

现在在控制器内

public function updateProductAPI(Request $request)
{
    // Get the id
    $id = $request->input('pid');
});
将API组合在一起的另一种方法是使用路由参数来处理ID或slug等唯一标识符

// The get call
$http.get('url/'+pid).then(function(data) { ... });

// routes.php
Route::get('url/{pid}', 'ProductController@updateProductAPI');

// Controller method
public function updateProductAPI($id, Request $request)
{
    // $id available here
}

传递到
$http.get
函数的第二个对象是配置对象。您需要在此对象上设置params属性,以便随请求发送数据

$http.get('url', { params : { pid : pid } });

现在在控制器内

public function updateProductAPI(Request $request)
{
    // Get the id
    $id = $request->input('pid');
});
将API组合在一起的另一种方法是使用路由参数来处理ID或slug等唯一标识符

// The get call
$http.get('url/'+pid).then(function(data) { ... });

// routes.php
Route::get('url/{pid}', 'ProductController@updateProductAPI');

// Controller method
public function updateProductAPI($id, Request $request)
{
    // $id available here
}