I am trying to set checkboxes checked based on database value. One user can have have multiple checkbox values.
Checkboxes are generated from database table called child_age_groups
:
@foreach ($child_age_groups as $age)
<div class="checkbox checkbox-info checkbox-inline">
<input class="age_group_checkbox" type="checkbox" name="age_group[]" id="age_group{{$age->id}}" "/>
<label for="age_group{{$age->id}}">{{$age->age_group}}</label>
</div>
@endforeach
So in my controller I get all the options that user has like this
$nanny_babysitting_ages = Nanny_babysitting_ages::where('user_id', user()->id)->get();
My nanny_babysitting_ages table is this
user_id | ages
and my child_age_groups table where I populate the checkboxes are this:
id | age_group
How can I set the checkboxes selcted based on the values from database?
if
in input like this :@if($age==$nanny_babysitting_ages->age ) CHECKED @endif
- Saman$nanny_babysitting_ages
from controller you can get$nanny_babysitting_ages
in view with something like :/App/Nanny_babysitting_ages::where('user_id', user()->id)->get();
- Saman