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