<form id="permission_input">
    @php
        $role_has_permission_ids = $role_has_permissions;
    @endphp

    @foreach ($permissions as $group_name => $permission)
        <h6 class="mb-2 mt-4"><strong>{{ $group_name }}</strong></h6>

        @foreach ($permission as $item)
            @php
                $checked = null;
                foreach ($role_has_permissions as $key => $value) {
                    if ($value->permission_id == $item->id) {
                        $checked = 'checked';
                        unset($role_has_permission_ids[$key]);
                    }
                }
            @endphp

            <div class="form-check">
                <input class="form-check-input" type="checkbox" value="{{ $item->id }}" id="check_{{ $item->id }}"
                    {{ $checked }}>
                <label class="form-check-label" for="check_{{ $item->id }}">{{ $item->display_name }}</label>
            </div>
        @endforeach
    @endforeach
</form>

<button type="button" class="btn btn-primary mt-3" id="save_permission">Update</button>
