Add a group to the user

@param $user_id
@param $group_id
@return mixed|void
@throws \Palmabit\Authentication\Exceptions\UserNotFoundException
762021
public function addGroup($user_id, $group_id) {
    try {
      $group = Group::findOrFail($group_id);
      $user = User::findOrFail($user_id);
      $user->addGroup($group);
    } catch (ModelNotFoundException $e) {
      throw new NotFoundException;
    }
  }
298413
public function giveGroupRole(int $group_id, int $role_id)
    {

        $group = Group::find($group_id);
        $role = RoleModel::firstOrNew(['id' => $role_id]);

        // If the role does not already have the group add it.
        if (! $role->groups->contains($group_id)) {
            $role->groups()->save($group);
            event(new UserGroupRoleAdded($group_id, $role));
        }
    }
626187
public function iHaveUserGroupWithIdInGroup( $name, $id, $parentGroup )
    {
        $userGroup = $this->getUserGroupManager()->ensureUserGroupExists( $name, $parentGroup );
        $this->addValuesToMap( $id, $userGroup->id );
    }
269094
public function editUser($user_id)
    {

        $user = $this->getFullUser($user_id);

        // get all groups except the one containing admin as admin account is special account
        // and the one to which the current user is already attached.
        $groups = $this->getAllGroups()->filter(function ($group, $key) use ($user_id) {

            return $group->users->where('name', 'admin')->isEmpty() && $group->users->where('id', $user_id)->isEmpty();
        });

        $login_history = $user->login_history()->orderBy('created_at', 'desc')->take(15)
            ->get();

        return view('web::configuration.users.edit',
            compact('user', 'groups', 'login_history'));
    }
292443
public function sync($userId, $groupInfo) {
    	try{
			if (empty($userId))
				throw new Exception('Paramer "userId" is required');

			if (empty($groupInfo))
				throw new Exception('Paramer "groupInfo" is required');


    		$params = array();
    			$params['userId'] = $userId;

           	foreach ($groupInfo as $key => $value) {
            	$params['group[' . $key . ']'] = $value;
           	}

    		$ret = $this->SendRequest->curl('/group/sync.json',$params,'urlencoded','im','POST');
    		if(empty($ret))
    			throw new Exception('bad request');
    		return $ret;

    	}catch (Exception $e) {
    		print_r($e->getMessage());
    	}
   }
977443
public function changeGroup ($userOpenID, $groupID)
    {
        $failed = $this->changeAllGroups([$userOpenID], $groupID);

        if (count($failed) <= 0) {
            return true;
        }

        return false;
    }
1249649
public function groupAdd($group_name){
        $params=array(
            'group_name'=>$group_name
        );
        $rst = $this->_request->post($this->_url . 'group/add', $params);
        return $this->_client->rst($rst);
    }
1201772
public function add_user_to_group($user, $groupid) {
        require_capability('moodle/course:managegroups', $this->context);
        $group = $this->get_group($groupid);
        if (!$group) {
            return false;
        }
        return groups_add_member($group->id, $user->id);
    }
691543
public function groupTransfer($group_id, $new_owner_user)
    {
        $url          = $this->url.'chatgroups/'.$group_id;
        $option       = [
            'newowner' => $new_owner_user
        ];
        $access_token = $this->getToken();
        $header []    = 'Authorization: Bearer '.$access_token;

        return Http::postCurl($url, $option, $header, 'PUT');
    }
921219
public function userKey($user_id, $key_id)
    {
        return $this->get('users/'.$this->encodePath($user_id).'/keys/'.$this->encodePath($key_id));
    }
1266355
public function removeGroup($userId, $groupId)
    {
        $qb = $this->createQueryBuilder();
        $qb->updateMany()
            ->field('_id')->equals(new \MongoId($userId))
            ->field('groups')->pull(array('$id' => new \MongoId($groupId)))
            ->getQuery()
            ->execute();
    }
1110893
public function addMember($groupId, $userId)
    {
        $exists = (bool)$this
            ->database
            ->query(
                "SELECT 1 FROM {ucms_group_access} WHERE group_id = :group AND user_id = :user",
                [':group' => $groupId, ':user' => $userId]
            )
            ->fetchField()
        ;

        if ($exists) {
            return false;
        }

        $this
            ->database
            ->merge('ucms_group_access')
            ->key([
                'group_id'  => $groupId,
                'user_id'   => $userId,
            ])
            ->execute()
        ;

        // @todo dispatch event

        $this->touch($groupId);

        $this->resetCache();

        return true;
    }
549413
public function groupUserGagRollback($userId,$groupId) {
        try{
            if(empty($userId))
                throw new Exception('用户 Id 不能为空');
            if(empty($groupId))
                throw new Exception('群组 Id 不能为空');
            $params['userId'] = $userId;
            $params['groupId'] = $groupId;
            $ret = $this->curl('/group/user/gag/rollback',$params);
            if(empty($ret))
                throw new Exception('请求失败');
            return $ret;
        }catch (Exception $e) {
            print_r($e->getMessage());
        }
    }
1023431
public Response addUserToGroup(String username, String groupName) {
		return restClient.post("users/" + username + "/groups/"+ groupName, null,
				new HashMap<String, String>());
	}
454374
public function addParticipant($userId)
    {
        $userIds = is_array($userId) ? $userId : (array) func_get_args();

        collect($userIds)->each(function ($userId) {
            Models::participant()->firstOrCreate([
                'user_id' => $userId,
                'thread_id' => $this->id,
            ]);
        });
    }
717227
protected function updateUser($user_id)
    {
        if (!$this->isError() && !$this->user->update($user_id, $this->getSubmitted())) {
            $this->errorAndExit($this->text('Unexpected result'));
        }
    }
69266
public function addGroupAction(Request $request, $groupId)
    {
        $format = $request->get('_format', 'json');
        $facade = $this->get('jms_serializer')->deserialize(
            $request->getContent(),
            $this->getParameter('open_orchestra_user_admin.facade.user_collection.class'),
            $format
        );
        $users = $this->get('open_orchestra_api.transformer_manager')->get('user_collection')->reverseTransform($facade);
        $group =  $this->get('open_orchestra_user.repository.group')->find($groupId);

        $this->get('open_orchestra_user.repository.user')->addGroup($users, $group);

        return array();
    }