public function attachUserToTeamByInvitation($invitationId, $user)
    {
        $userModel = get_class($user);

        $inviteModel = get_class((new $userModel)->invitations()->getQuery()->getModel());

        $invitation = (new $inviteModel)->where('token', $invitationId)->first();

        if ($invitation) {
            $invitation->team->users()->attach([$user->id], ['role' => Spark::defaultRole()]);

            $user->switchToTeam($invitation->team);

            $invitation->delete();
        }
    }
public function attachUserToTeamByInvitation($invitationId, $user)
    {
        $userModel = get_class($user);

        $inviteModel = get_class((new $userModel)->invitations()->getQuery()->getModel());

        $invitation = (new $inviteModel)->where('token', $invitationId)->first();

        if ($invitation) {
            $invitation->team->users()->attach([$user->id], ['role' => Spark::defaultRole()]);

            $user->switchToTeam($invitation->team);

            $invitation->delete();
        }
    }
public function attachUserToTeamByInvitation ( $ invitationId , $ user ) { $ userModel = get_class ( $ user ) ; $ inviteModel = get_class ( ( new $ userModel ) -> invitations ( ) -> getQuery ( ) -> getModel ( ) ) ; $ invitation = ( new $ inviteModel ) -> where ( 'token' , $ invitationId ) -> first ( ) ; if ( $ invitation ) { $ invitation -> team -> users ( ) -> attach ( [ $ user -> id ] , [ 'role' => Spark :: defaultRole ( ) ] ) ; $ user -> switchToTeam ( $ invitation -> team ) ; $ invitation -> delete ( ) ; } }
Attach a user to a given team based on their invitation.

@param  string  $invitationId
@param  \Illuminate\Contracts\Auth\Authenticatable  $user
@return void
Attach a user to a given team based on their invitation .