1 week ago

How do I match users permission with all the permissions in the database

Posted 1 week ago by Vusumzi

Hello guys, I'm trying to get the user role with permissions and compare them with all permissions that are in the database, if they match then a checkbox should be checked

My RoleController

 public function edit($id)
        $role =Role::where('id', $id)->with('permissions')->first();
        $permissions = Permission::all();
        return view('admin.roles.edit', compact('role', 'permissions'));


<table class="table">
                            <thead class="thead-dark">
                                    <th scope="col">TYPE</th>
                                    <th scope="col">CREATE</th>
                                    <th scope="col">VIEW</th>
                                    <th scope="col">UPDATE</th>
                                    <th scope="col">DELETE</th>
                            @foreach($permissions as $permission)
                                        <div class="custom-control custom-checkbox ml-3">
                                            <input type="checkbox" class="custom-control-input" id="{{ $permission->name }}" value="{{ ($permission->name) }}" {{ ($permission->name == "$role->permissions->name") ? "checked" : "" }}>
                                            <label class="custom-control-label" for="{{ $permission->name }}">{{ $permission->display_name }}</label>

I'm not getting any errors but I cant make the checkbox to be checked if they match

Please sign in or create an account to participate in this conversation.