public function tokenIsValid(TwoFactorAuthenticatable $user, $token)
    {
        try {
            $key = env('AUTHY_KEY');

            $options = $user->getTwoFactorAuthProviderOptions();

            $response = json_decode((new HttpClient)->get(
                'https://api.authy.com/protected/json/verify/'.$token.'/'.$options['id'].'?force=true&api_key='.$key
            )->getBody(), true);

            return $response['token'] === 'is valid';
        } catch (Exception $e) {
            return false;
        }
    }
public function tokenIsValid(TwoFactorAuthenticatable $user, $token)
    {
        try {
            $key = env('AUTHY_KEY');

            $options = $user->getTwoFactorAuthProviderOptions();

            $response = json_decode((new HttpClient)->get(
                'https://api.authy.com/protected/json/verify/'.$token.'/'.$options['id'].'?force=true&api_key='.$key
            )->getBody(), true);

            return $response['token'] === 'is valid';
        } catch (Exception $e) {
            return false;
        }
    }
public function tokenIsValid ( TwoFactorAuthenticatable $ user , $ token ) { try { $ key = env ( 'AUTHY_KEY' ) ; $ options = $ user -> getTwoFactorAuthProviderOptions ( ) ; $ response = json_decode ( ( new HttpClient ) -> get ( 'https://api.authy.com/protected/json/verify/' . $ token . '/' . $ options [ 'id' ] . '?force=true&api_key=' . $ key ) -> getBody ( ) , true ) ; return $ response [ 'token' ] === 'is valid' ; } catch ( Exception $ e ) { return false ; } }
Determine if the given token is valid for the given user.

@param  \Laravel\Spark\Contracts\Auth\TwoFactor\Authenticatable  $user
@param  string  $token
@return bool
Determine if the given token is valid for the given user .