Set checkboxes in Input :: all () in Laravel 4

I want to update my model with the following code:

$feature = Feature::find($id)->update(Input::all()); 

This works for all fields except the "done" field, which is logical in the table and is represented by a flag in the edit form.

 {{ Form::label('done', 'Done?')}} {{ Form::checkbox('done',1)}} 

How can I handle update flags and Input: all ()?

Thanks.

+7
php forms laravel
source share
3 answers

I found a workaround for this

 {{ Form::hidden('done', 0); }} {{ Form::checkbox('done', 1); }} 
+24
source share

I am doing a quick check before saving.

 if(!Input::get('someCheckbox')) $feature->someCheckbox = 0; 
+1
source share

I know this is old, but I found that this method works best when filling out form data.

 $myModel->fill(array_merge(['checkBoxName1'=>'0','checkBoxName2'=>'0'], $request->all())); 

or in the case of OP it will be like this:

  $feature = Feature::find($id)->update(array_merge(['checkBoxName1'=>'0','checkBoxName2'=>'0'],Input::all())); 

I just like it more than adding a hidden field.

+1
source share

All Articles