Form::model+checkbox in view Edit

Asked

Viewed 120 times

0

I’m using form::model for data editing. It works correctly but checkbox returns empty. How do I return the ones saved in bd?

I want them to show the ones who are registered. For example: in the course registration I marked Morning and Afternoon, so in the edition you have to return the two marked and one void, in the case Night.

[v] Morning [v] Evening [ ] Evening

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 resume only saved in the comic:

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

I don’t know how to do this.

1 answer

1

I finally managed to solve.

<?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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.