在Laravel中實現動態表單保存時如何處理每行多選下拉表格
<p>在我的表單中,我有一個動態表格,每一行中都有相同名稱的多重選擇下拉式選單color_id[]和size_id[]。我不知道如何將多個選擇的值保存為每一行中的逗號分隔的值儲存在資料庫中。我在這裡嘗試保存到資料庫,但是沒有起作用。 </p>
<p>HTML代碼:</p>
<pre class="brush:php;toolbar:false;"><table><tbody><td><select name="color_id[]" class="select2" id=" id=" id=" id=" id=" id=" id=" id=" id==d ;color_id" style="width:200px; height:100px;" required multiple></select></td><td> <</select></td><td> <select name=></td><td> <select name=></td><td> <select name=></td>&.. select2" id="size_id" style="width:200px; height:100px;" required multiple> </select></td></Hbody;<
<p>在控制器中儲存的Laravel程式碼:</p>
<pre class="brush:php;toolbar:false;">$class_ids = $request->input('class_ids');
for($x=0; $x<count($class_ids); $x ) {
# code...
$color_ids = implode(',', $request->color_id[$x]);
$size_ids = implode(',', $request->size_id[$x]);
$data3[]=array(
'bom_code'=>$TrNo,
'bom_date'=>$request->bom_date,
'cost_type_id'=>$request->cost_type_id,
'Ac_code'=>$request->Ac_code,
'season_id'=>$request->season_id,
'currency_id'=>$request->currency_id,
'item_code' => $request->item_codes[$x],
'class_id' => $request->class_ids[$x],
'description' => $request->descriptions[$x],
'color_id' => $color_ids,
'size_array' => $size_ids,
'consumption' => $request->consumptions[$x],
'unit_id'=> $request->unit_ids[$x],
'rate_per_unit' => $request->rate_per_units[$x],
'wastage' => $request->wastages[$x],
'bom_qty' => $request->bom_qtys[$x],
'total_amount' => $request->total_amounts[$x],
);
}
BOMSewingTrimsDetailModel::insert($data3);</pre>