我正在为一家制药公司建立一个销售点系统。我允许用户在购买新库存时添加更多字段,并希望将其添加到现有库存中。但我想一次提交所有这些,无论他们添加多少字段。我发现在控制器中很难做到这一点。
这是我的HTML
<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>
这是jQuery动态添加表单
$('#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();
}
我一直收到此错误Type error: Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, string given, called in