Exemple #1
0
 /**
  * Attach role to user.
  *
  * @param \Artesaos\Defender\Role $role
  * @param int                     $userId
  */
 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');
     }
 }
Exemple #2
0
 /**
  * Attach Permission to user.
  *
  * @param \Artesaos\Defender\Permission $permission
  * @param int                           $userId
  */
 protected function attachPermissionToUser($permission, $userId)
 {
     // Check if user exists
     if ($user = $this->userRepository->findById($userId)) {
         $user->attachPermission($permission);
         $this->info('Permission attached successfully to user');
     } else {
         $this->error('Not possible to attach permission. User not found');
     }
 }