coreui / coreui-free-laravel-admin-template

CoreUI Free Laravel Bootstrap Admin Template
https://coreui.io/laravel/
MIT License
621 stars 358 forks source link

Adding new user role with Menu Role #31

Open goodmuyis opened 4 years ago

goodmuyis commented 4 years ago

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' => 'super@example.net',
            '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');

rakieta2015 commented 4 years ago

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, 
    ]);