Form :: model + checkbox in view edit

0

I'm using form::model to edit data. It works correctly but the checkboxes return empty. How do I return the ones saved in bd?

I want them to show the ones that are registered. For example: in the course register I marked Morning and afternoon, so in the edition you have to return the two marked and one more empty, in the Night case.

  

[v] Morning [v] Afternoon [] Night

View edit:

{{ Form::model($curso, array('method' => 'PATCH', 'route' => array('painel.cursos.update', $curso->id))) }}
    <label>{{ Form::checkbox( 'turnos[0]', 'Manhã') }} Manhã</label>
    <label>{{ Form::checkbox( 'turnos[1]', 'Tarde') }} Tarde</label>
    <label>{{ Form::checkbox( 'turnos[2]', 'Noite') }} Noite</label>
{{ Form::close() }}

So they return empty.

Already in this way, they only retrieve the saved ones in bd:

<?php $course = explode(",", $curso->turno);?>
@foreach ($course as $c)
    <label>{{ Form::checkbox('turnos[]', $c, true) }} {{$c}}</label>
@endforeach

I'm not sure how to do this.

    
asked by anonymous 04.03.2014 / 21:22

1 answer

1

I finally got it sorted out.

<?php $array = explode(",", $curso->turno);?>
<label><input type="checkbox" name="turnos[]" value="Manhã" <?php if(in_array('Manhã', $array)) echo( 'checked = "checked"'); ?>/> Manhã</label>
<label><input type="checkbox" name="turnos[]" value="Tarde" <?php if(in_array('Tarde', $array)) echo( 'checked = "checked"'); ?>/> Tarde</label>
<label><input type="checkbox" name="turnos[]" value="Noite" <?php if(in_array('Noite', $array)) echo( 'checked = "checked"'); ?>/> Noite</label>
    
06.03.2014 / 01:17