I have an edit form containing several checkboxes. When I try to update the form with any of the checkboxes left 'unchecked', I get an "undefined index" error for that particular checkbox. When I initially store new data, 'unchecked' checkboxes are stored just fine. It's only an issue if I try to edit data and leave checkboxes 'unchecked'.
I've tried using the '{{Form::hidden(fieldname, 0) }}' method but it hasn't been working for me.
edit-album.blade.php(View):
{{ Form::model($album, array('method' => 'PUT', 'route' => array('edit_album2', $album->album_id))) }}
<div class ="form-group">
{{ Form::checkbox('album_application_kitchen', 'Kitchen') }}
{{ Form::label('album_application_kitchen', 'Kitchen') }}
{{ Form::checkbox('album_application_bathroom', 'Bathroom') }}
{{ Form::label('album_application_bathroom', 'Bathroom') }}<br />
</div>
{{ Form::close() }}
EditAlbumsController2.php(Controller):
public function update($id) {
$input = \Input::all();
$validation = new Validators\Album($input);
if ($validation->passes())
{
$album = Album::find($id);
$album->album_application_kitchen = $input['album_application_kitchen'];
$album->album_application_bathroom = $input['album_application_bathroom'];
$album->touch();
$album->save();
return \Redirect::route('gallery.album.show', array('id' => $id));
}
else
{
/* Code for when validation fails */
}
}
Is there a special trick to solve this problem or am I just not using the {{Form::hidden()}} structure properly?