Php 使用AngularJS在数据库中存储数据&;拉维尔5号
我有一个这样的设置Php 使用AngularJS在数据库中存储数据&;拉维尔5号,php,angularjs,laravel,Php,Angularjs,Laravel,我有一个这样的设置 $scope.storePlatesInspection = function() { PlatesInspectionFactory.inspectionUpdate($scope.inspectionData) .success(function(data) { $scope.ServerResponse = data; sweetAlert('Nailed it!', 'Your entered data was send to
$scope.storePlatesInspection = function() {
PlatesInspectionFactory.inspectionUpdate($scope.inspectionData)
.success(function(data)
{
$scope.ServerResponse = data;
sweetAlert('Nailed it!', 'Your entered data was send to database', 'success');
console.log($scope.inspectionData);
})
.error(function(data) {
sweetAlert("Oops...", "Something went wrong!", "error");
console.log($scope.inspectionData);
});
};
我的html
<div class="panel-body">
<div class="form-group form-group-lg">
<label class="col-sm-2 control-label">Select a plate</label>
<div class="col-sm-10">
<select class="form-control m-t" id="plate_id" ng-model="inspectionData.plate" ng-options="plate as (plate.serial_number) for plate in plates" required>
<option value="">Please choose
<span class="symbol required"></option>
</select>
</div>
</div>
</div>
我的服务
inspectionUpdate: function(inspectionData) {
return $http({
url: '/api/v1/plateinspection/',
method: 'PUT',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
data: $.param(inspectionData)
});
}
我只想获取所选数据并通过API将其发送回并保存
我对如何捕捉从角度发送的所有对象感到困惑
这就是我一直在尝试的
public function storePlateInspectionData(){
$plate = Plate::find($request->input('plate_id'));
$doc = Document::find($request->input('document_id'));
$plate->documents()->attach($doc->id);
}
我应该使用Input::all()
还是request->all()
这样做的最佳实践是什么
$request->input('plate_id)
不工作。有人请帮忙
这是我在控制台中得到的
在这种情况下,我希望id
即3
来保存数据。我怎样才能做到这一点
更新状态代码500
在您的公共函数storePlateInspectionData()
上,您没有传递请求,那么$request
来自哪里?您的函数应该是这样的->公共函数storePlateInspectionData(Request$Request)
@FabioAntunes我在构造函数中传递$Request
。这不是问题所在。当plate
对象进入时,我需要到达它的id
,即3
。那么我们该怎么做呢?我尝试了$data=$request->all()
和$data['plate\u id']
,但没有成功:(首先做var\u转储($request->all());die;
在你的storePlateInspectionData
上,检查它是否接收到任何数据;@Fabioantune不确定如何调试此数据。我正在填写前端的from,如何确保后端接收到它?我不确定var_dump
是否会将其剪切。如果var_dump为空,则是因为你的计算机上没有接收到任何数据后端,只需使用chrome开发工具并在公共函数storePlateInspectionData()
上检查您的网络面板,您没有传递请求,那么$request
从何而来?您的函数应该是这样的->公共函数storePlateInspectionData(request$request)
@FabioAntunes我在构造函数中传递$request
。这不是问题。当plate
对象进来时,我需要到达它的id
,即3
。那么怎么做呢?我已经尝试了$data=$request->all()
和$data['plate\id']
但不起作用:(首先执行var\u转储($request->all());die;
在你的storePlateInspectionData
上,检查它是否接收到任何数据;@Fabioantune不确定如何调试此数据。我正在填写前端的from,如何确保后端接收到它?我不确定var_dump
是否会将其剪切。如果var_dump为空,则是因为你的计算机上没有接收到任何数据后端,只需使用chrome开发工具并检查您的网络窗格