Sunday, April 16, 2017

Laravel 5.2 :get checkbox checked

I am trying to get checkbox as checked

Here is my view

<div class="form-group">
                {!! Form::label('extra_services', 'Add extra services') !!}
                <div class="form-group">
                    <?php var_dump (array($temp->extra_services))?>
                    @foreach($extra as $ext)
                        <div class="checkbox">
                            <label>
                                {!! Form::hidden('extra_services', 0) !!}
                                <input type="checkbox" name="extra_services[]" value="{!! $ext->id !!}"
                                       {!! in_array($ext->id, array($temp->extra_services)) ? 'checked' : '' !!} >
                                {!! $ext->title !!}
                            </label>
                        </div>
                    @endforeach
                </div>
            </div>

when I dump my $temp->extra_services I got array(1) { [0]=> string(3) "1,2" }

but in the view the first checkbox only checked the second is not which it should be check too.

what I am doing wrong here.



via Yousef Altaf

Advertisement