src/Mpociot/Teamwork/Teamwork.php
public function inviteToTeam( $user, $team = null, callable $success = null )
    {
        if ( is_null( $team ) )
        {
            $team = $this->user()->current_team_id;
        } elseif( is_object( $team ) )
        {
            $team = $team->getKey();
        }elseif( is_array( $team ) )
        {
            $team = $team["id"];
        }

        if( is_object( $user ) && isset($user->email) )
        {
            $email = $user->email;
        } elseif( is_string($user) ) {
            $email = $user;
        } else {
            throw new \Exception('The provided object has no "email" attribute and is not a string.');
        }

        $invite               = $this->app->make(Config::get('teamwork.invite_model'));
        $invite->user_id      = $this->user()->getKey();
        $invite->team_id      = $team;
        $invite->type         = 'invite';
        $invite->email        = $email;
        $invite->accept_token = md5( uniqid( microtime() ) );
        $invite->deny_token   = md5( uniqid( microtime() ) );
        $invite->save();

        if ( !is_null( $success ) )
        {
            event(new UserInvitedToTeam($invite));
            return $success( $invite );
        }
    }
public function inviteToTeam( $user, $team = null, callable $success = null )
    {
        if ( is_null( $team ) )
        {
            $team = $this->user()->current_team_id;
        } elseif( is_object( $team ) )
        {
            $team = $team->getKey();
        }elseif( is_array( $team ) )
        {
            $team = $team["id"];
        }

        if( is_object( $user ) && isset($user->email) )
        {
            $email = $user->email;
        } elseif( is_string($user) ) {
            $email = $user;
        } else {
            throw new \Exception('The provided object has no "email" attribute and is not a string.');
        }

        $invite               = $this->app->make(Config::get('teamwork.invite_model'));
        $invite->user_id      = $this->user()->getKey();
        $invite->team_id      = $team;
        $invite->type         = 'invite';
        $invite->email        = $email;
        $invite->accept_token = md5( uniqid( microtime() ) );
        $invite->deny_token   = md5( uniqid( microtime() ) );
        $invite->save();

        if ( !is_null( $success ) )
        {
            event(new UserInvitedToTeam($invite));
            return $success( $invite );
        }
    }
public function inviteToTeam ( $ user , $ team = null , callable $ success = null ) { if ( is_null ( $ team ) ) { $ team = $ this -> user ( ) -> current_team_id ; } elseif ( is_object ( $ team ) ) { $ team = $ team -> getKey ( ) ; } elseif ( is_array ( $ team ) ) { $ team = $ team [ "id" ] ; } if ( is_object ( $ user ) && isset ( $ user -> email ) ) { $ email = $ user -> email ; } elseif ( is_string ( $ user ) ) { $ email = $ user ; } else { throw new \ Exception ( 'The provided object has no "email" attribute and is not a string.' ) ; } $ invite = $ this -> app -> make ( Config :: get ( 'teamwork.invite_model' ) ) ; $ invite -> user_id = $ this -> user ( ) -> getKey ( ) ; $ invite -> team_id = $ team ; $ invite -> type = 'invite' ; $ invite -> email = $ email ; $ invite -> accept_token = md5 ( uniqid ( microtime ( ) ) ) ; $ invite -> deny_token = md5 ( uniqid ( microtime ( ) ) ) ; $ invite -> save ( ) ; if ( ! is_null ( $ success ) ) { event ( new UserInvitedToTeam ( $ invite ) ) ; return $ success ( $ invite ) ; } }
Invite an email adress to a team.
Either provide a email address or an object with an email property.

If no team is given, the current_team_id will be used instead.

@param string|User $user
@param null|Team $team
@param callable $success
@throws \Exception
Invite an email adress to a team . Either provide a email address or an object with an email property .