我想把数据保存到数据库里。通过动态窗体保存许多行,但我尝试的是无效的
请介绍我,我是初学者。
形式:
<form class="form-ajax" action="/standard_sub" method="POST" name="add_name" id="add_name">
@csrf()
<td><input type="text" name="standard_sub_code[]" placeholder="Enter your Subcode" class="form-control name_list" /></td>
<td><input type="text" name="standard_sub_name[]" placeholder="Enter your Subname" class="form-control code_list" /></td>
<td>
<select class="form-control">
<option value="all">
ทั้งหมด
</option>
@foreach($standard_main as $index => $row)
<option name="standard_main_id[]" value="{{$row->standard_main_id}}">
{{$row->standard_main_code}} {{$row->standard_main_name}}
</option>
@endforeach
</select>
</td>
<td><button type="button" name="add" id="add" class="btn btn-success">Add More</button></td>
</div>
</form>
控制器:
public function store(Request $request)
{
$standard_sub_code = $request->get('standard_sub_code');
$standard_sub_name = $request->get('standard_sub_name');
$standard_main_id = $request->get('standard_main_id');
if(is_array($standard_sub_code) && is_array($standard_sub_name) && is_array($standard_main_id))
{
DB::table('standard_sub')->insert([
'standard_sub_code' =>$standard_sub_code,
'standard_sub_name' =>$standard_sub_name,
'standard_main_id' =>$standard_main_id,
'created_at' =>date('Y-m-d H:i:s'),
]);
}
暂无答案!
目前还没有任何答案,快来回答吧!