我想在数据库中同时在多行中插入多个复选框值。我得到复选框的值,当提交表单时,它将空值存储在数据库中。我想我无法将视图中的复选框值传递给控制器.... 这是我的控制器代码:
`public function create(Request $request) {`
`$treatment_id = json_decode(Input::get('treatment_id'), true);
//assuming you use json to submit the multiple countries`
$user_countries = array();
foreach($countries as $country)
{
$treatment_id[]=new Price(array('treatment_id'=>$treatment_id));
}
//save the countries into the DB
$user->prices()->saveMany($treatment_id);
$count=$request->input('counter');
for ($i=1; $i<=$count; $i++) {
$prices= new Price;
$hospital_id=$request->input('hospital_id');
$category_id=$request->input('category_id');
$treatment_id=$request->input('treatment_id');
$price=$request->input('price');
$prices->hospital_id=$hospital_id;
$prices->category_id=$category_id;
$prices->treatment_id=$treatment_id;
$prices->price=$price;
$prices->save();
}
return view('admin.viewprice');
}
这是我的视图/刀片代码:在此页面中,我使用productname
类部分中的ajax获取输入复选框值名称或价格部分
<form role="form" action="{{route('createprice')}}" method="POST" enctype="multipart/form-data">
{{ csrf_field() }}
<input type="hidden" name="counter" id="counter" value="1" />
<select class="form-control" name="hospital_id">
@foreach($hospitals as $key=> $hospital)
<option value="{{$hospital->id}}">{{$hospital->hospital_name}}</option>
@endforeach
</select>
<select style="width:200px;" class="productcategory form-control" id="prod_cat_id" name="category_id">
<option value="0" disabled="true" selected="true">--Select--</option>
@foreach($categories as $key=> $category)
<option value="{{$category->id}}">{{$category->name}}</option>
@endforeach
</select>
<div class="productname" id="add_schedule">
</div>
`Ajax Request`
op+='<option value="0" selected disabled> Chose Product</option>';
for(var i=1; i<data.length; i++) {
document.getElementById('counter').value = i;
op+='<div class="col-md-4"><input type="checkbox" name="treatment_id[]" value="'+data[i].id+'">'+data[i].treatment_name+'</div> '+'<div class="col-md-4"><input type="text" name="price[]" /></div>';
我不知道自己哪里弄错了......如果有人有解决方案的话请帮帮我....