Javascript 将参数传递到要编辑的Laravel的角度
我使用的是Laravel5.1,请求如何通过api调用接受angular传递的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
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
}