我是新的laravel.this是我的看法形式Laravel 5.3 - 插入數據,以多行
<div class="row">
<div class="col-md-6">
<form class="" action="{{route('production.update', $rm->id)}}" method="post">
<input name="_method" type="hidden" value="PATCH">
{{csrf_field()}}
<input type="hidden" name="id" id="id" class="form-control" value="{{$rm->id}}">
<div class="form-group{{ ($errors->has('batch_id')) ? $errors->first('title') : '' }}">
<lable>Batch ID</lable>
<input type="text" name="batch_id" id="batch_id" class="form-control" value="{{$rm->product_id}}" readonly="">
{!! $errors->first('wastage','<p class="help-block">:message</p>') !!}
</div>
<div class="form-group{{ ($errors->has('')) ? $errors->first('title') : '' }}">
<lable>Packing</lable>
@foreach($subitem as $sub)
<div class="row">
<div class="col-md-4">
<input type="checkbox" name="subitem[i]" value="{{$sub->id}}"> {{$sub->subitem_name}}
<div class="col-md-4">
<input type="text" name="qty[i]" id="qty" class="form-control" placeholder="Entire Qty">
{!! $errors->first('qty','<p class="help-block">:message</p>') !!}
</div>
</div>
@endforeach
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Add">
</div>
</form>
</div>
</div>
</div>
我需要做的,當我點擊添加按鈕,插入BATCH_ID,sub_id和數量的倍數行.batch_id是相同和數量,sub_id是差異。請問誰能幫我做到這一點?
我還需要改變我的控制器,
public function update(Request $request, $id)
{
$items = new Itempacking;
$items->batch_id = $request->batch_id;
$items->sub_id = $request->sub_id
$items->quantity = $request->quantity;
$items->save();
}
任何人都可以幫助嗎?
嘗試改變'NAME = 「子項[I]」'和'名=「subitem []」'和'qty'也使用你在數組中傳遞數據,所以你需要foreach循環來添加多個數據。 – Nidhi