I have a survey form and I need to put the value in one column based on checkbox value.
My input form for the checkbox:
<input type="checkbox" name="chk" value="1" />
<label for="chk[]">Prijava</label>
Controller:
public function store(Request $request)
{
$validated=$request->validate([
'title'=>'required',
'description'=>'nullable'
]);
if(Input::get('chk')==="1"){
$validated['prijava']=1;
}
else{
$validated['prijava']=0;
}
return Survey::create($validated);
}
I need the 'prijava' column to be 1 if checkbox is check or 0 if not. I always get 0 and if I change code in else to for example 2, it will add 2 in column. I also put 'prijava' column to be a boolean.