I tried different ways to save multiple checkbox into database. I am so close right now but just last checkbox value are saving into database. I want them all and i couldn't make it. Here is my html codes.
<div class="col-xl-12">
<label>1st</label>
<input type="checkbox" name="data[]" value="00101"/>
<label>2nd</label>
<input type="checkbox" name="data[]" value="00102"/>
<label>3rd</label>
<input type="checkbox" name="data[]" value="00103"/>
<label>4th</label>
<input type="checkbox" name="data[]" value="00104"/>
</div>
In my controller.
public function store(Request $request)
{
$this->validate($request, array(
'staff' => 'nullable',
'dmc' => 'nullable',
'workdone' => 'nullable',
'product_id' => 'nullable'
));
$ltjob = new Ltjob;
$ltjob->staff = $request->staff;
$ltjob->dmc = $request->dmc;
$ltjob->product_id = $request->product_id;
foreach ($request->input("data") as $data){
$ltjob->workdone= $data;
}
$ltjob->save();
return redirect()->route('ltjobs.create');
}
Still saving last checkbox. When i try the dd($request->input("data"));
before the foreach it gives me this:
array:3 [▼
0 => "00101"
1 => "00102"
2 => "00104"
]
And saving 00104. I hope you guys find the solution. And so sorry for my bad english. Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire