Jquery Laravel 5.4动态表单将数据保存到数据库
我正在为一家制药公司建立一个销售点系统。我允许用户在购买新股票并希望将其添加到现有股票时添加更多字段。但我想一次提交所有这些内容,不管它们添加了多少字段。我发现在控制器中很难做到这一点 这是我的HTMLJquery Laravel 5.4动态表单将数据保存到数据库,jquery,laravel-5.4,Jquery,Laravel 5.4,我正在为一家制药公司建立一个销售点系统。我允许用户在购买新股票并希望将其添加到现有股票时添加更多字段。但我想一次提交所有这些内容,不管它们添加了多少字段。我发现在控制器中很难做到这一点 这是我的HTML <div class="container"> <div class=""> <div class="row"> <div class="col-md-8 col-md-offset-2 shad-content">
<div class="container">
<div class="">
<div class="row">
<div class="col-md-8 col-md-offset-2 shad-content">
<div class="panel-heading "><h3>Please add new drugs</h3></div>
<div class="panel-body">
<form action="{{ route('post-new-products') }}" method="POST">
{{ csrf_field() }}
<table id="add-me" class="table table-bordered">
<thead>
<tr>
<th>Quantity</th>
<th>Description</th>
<th>Selling Price</th>
<th>Actions</th>
</tr>
</thead>
<tbody >
<tr>
<td id="quantity" class="col-md-2"><input onkeypress='return event.charCode >= 48 && event.charCode <=57' type="text" name="quantity[]" class="form-control" autofocus="" /></td>
<td class="col-md-7"><input type="text" name="description[]" class="form-control" /></td>
<td class="col-md-3"><input type="text" name="selling_price[]" class="form-control" /></td>
<td class="col-md-2">
<button type="button" class="btn btn-danger">
Delete</button>
</td>
</tr>
</tbody>
</table>
<div class="action-buttons">
<button id="add-form" type="button" class="btn btn-default">Add New Form</button>
<button type="submit" class="btn btn-success">Save All Drugs</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
我不断得到这个错误
类型错误:传递给illumb\Database\Grammar::parameterie()的参数1必须是数组类型,字符串给定,调用于
数据保存中有任何错误吗?这是错误类型错误:传递给illumb\Database\Grammar::parameterie()的参数1必须是数组类型,字符串给定,在
中调用时,别忘了将i添加到输入名称和ID中。你能在没有i的情况下添加($request)吗?我可以在没有i的情况下获得所有相应的数据。但是我不知道为什么它不能保存。你能举个例子吗?html和控制器
$('#add-form').click(function() {
i++;
$('#add-me').append(
'<tbody id="row'+i+'"><tr>'+
'<td class="col-md-2">'+
'<input id="quantity" onkeypress="return event.charCode >= 48 && event.charCode <=57" type="text" name="quantity[]" class="form-control"/>'
+'</td>'
+'<td class="col-md-7">'
+'<input type="text" name="description[]" class="form-control"/>'
+'</td>'
+'<td class="col-md-3">'
+'<input type="text" name="selling_price[]" class="form-control" />'
+'</td>'
+'<td class="col-md-2">'
+'<button id="'+i+'" type="button" class="btn btn-danger delegated-btn">Delete</button>'
+'</td>'
+'</tr></tbody>'
);
});
public function createInventory(Request $request) {
$product = new Product;
$product->quantities = $request->get('quantity');
$product->description = $request->get('description');
$product->selling_price = $request->get('selling_price');
$product->save();
}