vendredi 22 avril 2016

Laravel checkobx in build form doesn't update value

In Laravel I'm using Form builder. My form is same for creating and updating post. In that form I create checkbox for enabling/disabling comments in post. Default value is 1 (checked). Checkbox works fine when I'm creating new post. Also when I load edit page, if in post from database is enabled comment, page load checked box and if in post is disabled comments page load unchecked box. Problem is when I want to edit and change this and update post. Enable comments value not changing. There is no any error and changed values from other form fields are store correctly. Column name is enable_comments - boolean type and this is my form builder input field code:

{!! Form::label('enable_comments') !!}
{!! Form::checkbox('enable_comments', $post->exists ? $post->enable_comments : 1, !$post->exists ? true : $post->enable_comments) !!}

Note, everything works fine on creating post. If checkbox is checked, it store 1 in database, if it's not, it store 0. Also, it display correct on editing page. If "enable_comments" value in database is 1, it's checked on edit page, if it's 0, checkbox is unchecked.

Please help. Where I'm making wrong? Where is a problem in this logic?




Aucun commentaire:

Enregistrer un commentaire