src/Defender/Commands/MakeRole.php
protected function attachRoleToUser($role, $userId)
    {
        // Check if user exists
        if ($user = $this->userRepository->findById($userId)) {
            $user->attachRole($role);
            $this->info('Role attached successfully to user');
        } else {
            $this->error('Not possible to attach role. User not found');
        }
    }
protected function attachRoleToUser($role, $userId)
    {
        // Check if user exists
        if ($user = $this->userRepository->findById($userId)) {
            $user->attachRole($role);
            $this->info('Role attached successfully to user');
        } else {
            $this->error('Not possible to attach role. User not found');
        }
    }
protected function attachRoleToUser ( $ role , $ userId ) { // Check if user exists if ( $ user = $ this -> userRepository -> findById ( $ userId ) ) { $ user -> attachRole ( $ role ) ; $ this -> info ( 'Role attached successfully to user' ) ; } else { $ this -> error ( 'Not possible to attach role. User not found' ) ; } }
Attach role to user.

@param \Artesaos\Defender\Role $role
@param int                     $userId
Attach role to user .