src/Mpociot/Teamwork/Traits/UserHasTeams.php
public function switchTeam( $team )
    {
        if( $team !== 0 && $team !== null )
        {
            $team        = $this->retrieveTeamId( $team );
            $teamModel   = Config::get( 'teamwork.team_model' );
            $teamObject  = ( new $teamModel() )->find( $team );
            if( !$teamObject )
            {
                $exception = new ModelNotFoundException();
                $exception->setModel( $teamModel );
                throw $exception;
            }
            if( !$teamObject->users->contains( $this->getKey() ) )
            {
                $exception = new UserNotInTeamException();
                $exception->setTeam( $teamObject->name );
                throw $exception;
            }
        }
        $this->current_team_id = $team;
        $this->save();

        if( $this->relationLoaded('currentTeam') ) {
            $this->load('currentTeam');
        }
        
        return $this;
    }
public function switchTeam( $team )
    {
        if( $team !== 0 && $team !== null )
        {
            $team        = $this->retrieveTeamId( $team );
            $teamModel   = Config::get( 'teamwork.team_model' );
            $teamObject  = ( new $teamModel() )->find( $team );
            if( !$teamObject )
            {
                $exception = new ModelNotFoundException();
                $exception->setModel( $teamModel );
                throw $exception;
            }
            if( !$teamObject->users->contains( $this->getKey() ) )
            {
                $exception = new UserNotInTeamException();
                $exception->setTeam( $teamObject->name );
                throw $exception;
            }
        }
        $this->current_team_id = $team;
        $this->save();

        if( $this->relationLoaded('currentTeam') ) {
            $this->load('currentTeam');
        }
        
        return $this;
    }
public function switchTeam ( $ team ) { if ( $ team !== 0 && $ team !== null ) { $ team = $ this -> retrieveTeamId ( $ team ) ; $ teamModel = Config :: get ( 'teamwork.team_model' ) ; $ teamObject = ( new $ teamModel ( ) ) -> find ( $ team ) ; if ( ! $ teamObject ) { $ exception = new ModelNotFoundException ( ) ; $ exception -> setModel ( $ teamModel ) ; throw $ exception ; } if ( ! $ teamObject -> users -> contains ( $ this -> getKey ( ) ) ) { $ exception = new UserNotInTeamException ( ) ; $ exception -> setTeam ( $ teamObject -> name ) ; throw $ exception ; } } $ this -> current_team_id = $ team ; $ this -> save ( ) ; if ( $ this -> relationLoaded ( 'currentTeam' ) ) { $ this -> load ( 'currentTeam' ) ; } return $ this ; }
Switch the current team of the user

@param object|array|integer $team
@return $this
@throws ModelNotFoundException
@throws UserNotInTeamException
Switch the current team of the user