coreui-free-laravel-admin-template icon indicating copy to clipboard operation
coreui-free-laravel-admin-template copied to clipboard

Adding new user role with Menu Role

Open goodmuyis opened this issue 4 years ago • 1 comments

Using the code below, I was able to add a new user with new role in to the database. But the problem is the Menu is not visible or added to the sidebar for the users with additional role. everything is working for the default user and admin roles.

What am I missing here

        $user = User::create([
            'name' => 'APP Admin',
            'email' => '[email protected]',
            'email_verified_at' => now(),
            'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
            'remember_token' => Str::random(10),
            'menuroles' => 'user,siteadmin,tutor'
        ]);
        $user->assignRole('user'); 
        $user->assignRole('siteadmin');
        $user->assignRole('tutor'); 

Edit: I have looked into the MenusTableSeeder.php to adjust the menuroles string but the menu items are not visible if user string is not added, user is the lowest roles

There is also an instance where $this->insertLink('admin,siteadmin,tutor', 'Add a Class', '/classroom/add');

goodmuyis avatar Jun 03 '20 16:06 goodmuyis

The more important the role is, the higher it should be in the hierarchy. The guest role should be at the end of the hierarchy. For example:

    $x = Role::create(['name' => 'siteadmin']);
    RoleHierarchy::create([
        'role_id' => $x->id,
        'hierarchy' => 1,
    ]);
    $x = Role::create(['name' => 'tutor']); 
    RoleHierarchy::create([
        'role_id' => $x->id,
        'hierarchy' => 2,
    ]);
    $adminRole = Role::create(['name' => 'admin']);
    RoleHierarchy::create([
        'role_id' => $adminRole->id,
        'hierarchy' => 3,
    ]);
    $userRole = Role::create(['name' => 'user']);
    RoleHierarchy::create([
        'role_id' => $userRole->id,
        'hierarchy' => 4,
    ]);
    $guestRole = Role::create(['name' => 'guest']); 
    RoleHierarchy::create([
        'role_id' => $guestRole->id,
        'hierarchy' => 5, 
    ]);

rakieta2015 avatar Jun 06 '20 08:06 rakieta2015