mardi 1 septembre 2015

Laravel 5.1 How to validate that at least one checkbox is checked in a form request?

I have a form in which the user should at least select one of the check boxes. This is the code for generating a group of check boxes in the view:

    <div class="form-group">
          @foreach($subjects as $subject)
            <label>{!! Form::checkbox('subject[]', $i++, null,  ['id' => 'subject']) !!} {!! $subject !!} </label>
                @if($i%10==0)
                   {!! "<br />" !!}
                @endif
          @endforeach

    </div>

For now if the user does not select a subject the subject index will not set so there will be nothing to be validated. How can I validate that the user has selected at least one subject?




Aucun commentaire:

Enregistrer un commentaire