Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

forms

php

laravel

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.

like image 737
Bernd Strehl Avatar asked Aug 20 '13 09:08

Bernd Strehl


3 Answers

I found a workaround for this

{{ Form::hidden('done', 0); }}
{{ Form::checkbox('done', 1); }}
like image 158
Bernd Strehl Avatar answered Nov 10 '22 01:11

Bernd Strehl


I'm making a quick check before saving.

if(!Input::get('someCheckbox')) $feature->someCheckbox = 0;
like image 27
Boris Avatar answered Nov 10 '22 00:11

Boris


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.

like image 1
Eldar Gerfanov Avatar answered Nov 10 '22 02:11

Eldar Gerfanov