Vusumzi
1 week ago
114
6
Laravel

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'));
    }

edit.blade.php

<table class="table">
                            <thead class="thead-dark">
                                <tr>
                                    <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>
                                </tr>
                            </thead>
                            <tbody>
                            @foreach($permissions as $permission)
                                <tr>
                                    <td>
                                        <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>
                                        </div>
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                         </table>

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.