I want to update my model with following code:
$feature = Feature::find($id)->update(Input::all());
This works for all fields except the "done"-field which is a boolean in the table and represented by checkbox in the edit form.
{{ Form::label('done', 'Done?')}}
{{ Form::checkbox('done',1)}}
How can i handle checkboxes with update and Input:all() ?
Thank you.
I found a workaround for this
{{ Form::hidden('done', 0); }}
{{ Form::checkbox('done', 1); }}
I'm making a quick check before saving.
if(!Input::get('someCheckbox')) $feature->someCheckbox = 0;
I know this is old one, but i found this way works best when filling form data
$myModel->fill(array_merge(['checkBoxName1'=>'0','checkBoxName2'=>'0'], $request->all()));
or in case of the OP it would be like this:
$feature = Feature::find($id)->update(array_merge(['checkBoxName1'=>'0','checkBoxName2'=>'0'],Input::all()));
I just like it way more than adding a hidden field.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With