Getting a checkbox checked

I have group of checkbox which I add to database as an array [1,2,3] everything going OK when I adding it but what about retrieve it from the database to edit.

here is my controller

public function edit($id)
        $temp = Template::query()->findOrFail($id);
        $extra = TempExtraService::all();
        return view('admin.templates.tempDetails.edit', compact('temp', 'extra'));

and here is my view

<div class="form-group">
                {!! Form::label('extra_services', 'Add extra services') !!}
                <div class="form-group">
                    @foreach($extra as $ext)
                        <div class="checkbox">
                                {!! Form::hidden('extra_services[]', 0) !!}
                                {!! Form::checkbox('extra_services[]', $ext->id, $temp->extra_services, ['class' => 'checkbox'])  !!}
                                {!! $ext->title !!}

I get all the checkbox s checked even if they are not even review the table after editing got something like this 0,1,0,2,0

rowright replied 1 year ago

It looks like the $extra is generating multiple Extra Service rows, however the same value from the $temp/Template is being passed though to each as your doing a "->findOrFail()". I'm not sure how the data is stored here, but I'd check where you are pulling in the boolean for each Extra Service and get that data available.

Sign in to participate in this thread!

We'd like to thank these amazing companies for supporting us