我有一个表格如下
<form method="POST" name="addItem" role="form" ng-submit="saveAdd()">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Create Item</h4>
</div>
<div class="modal-body">
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-6">
<strong>Category : </strong>
<div class="form-group">
<select ng-model="form.cid" placeholder="Category" name="cid" class="form-control" required >
<option value="1">abc</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-6">
<strong>Title : </strong>
<div class="form-group">
<input ng-model="form.title" type="text" placeholder="Name" name="title" class="form-control" required />
</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-6">
<strong>Description : </strong>
<div class="form-group" >
<textarea ng-model="form.description" class="form-control" required>
</textarea>
</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-6">
<strong>Alias : </strong>
<div class="form-group" >
<textarea ng-model="form.item_alias" class="form-control" required>
</textarea>
</div>
</div>
</div>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" ng-disabled="addItem.$invalid" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
并且angluarjs函数会将数据传递给laravel后端。
$scope.saveAdd = function(){
dataFactory.httpRequest('items','POST',{},$scope.form).then(function(data) {
$scope.data.push(data);
$(".modal").modal("hide");
});
}
laravel后端错误:
a foreign key constraint fails (`laravel_ang`.`items`, CONSTRAINT
`items_cid_foreign` FOREIGN KEY (`cid`) REFERENCES `category` (`id`)) (SQL:
insert into `items` (`title`, `description`, `item_alias`, `updated_at`,
`created_at`) values (test, 123, 23, 2016-11-12 09:41:35, 2016-11-12 09:41:35))
在laravel路线上,它是一个资源控制器:
Route::resource('items', 'ItemController');
在控制器中,功能:
public function store(Request $request)
{
$input = $request->all();
$create = Item::create($input);
return response($create);
}
在insert语句中包含cid的任何想法?