PHP code example of larakeeps / authguard-otp

1. Go to this page and download the library: Download larakeeps/authguard-otp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

larakeeps / authguard-otp example snippets


use Larakeeps\AuthGuard\Facades\OTP;

/** 
 * 
 * The create method has 3 parameters, 1 mandatory and 2 optional.
 * 
 * The $reference parameter is used with the assertive condition function in code validation.
 * The $email parameter is used in the same way as the $reference parameter
 * 
 * @param string $phone : * 
 * The then method returns 2 parameters, $data of type AuthGuard, and $response of type Collection.
 * 
 * @method then(Closure $destination)
 * 
 * */
 
$createOTP->then(function (AuthGuard|null $data, Collection $response){
       
       /*
        * the $data parameter returns the null or Authguard model containing the table columns.
        */
       
       /*
        * The $response parameter returns a collection containing the following data: 
        * number_digits, code, message, status, user.access_token, user.ip_address
        */
        
        return $data->expires_at; // returns a value of type Carbon::class;
        
        if($response->status){
            return $response->message;
        }
       
});

// OR through the get() method that returns a Collection

return $createOTP->get();

// OR like this

return OTP::get();


// OR through the getResponse() method that returns a Collection

return $createOTP->getResponse();

// OR like this

return OTP::getResponse();


// OR can be called individually using methods

return OTP::getData()->expires_at; // returns a value of type Carbon::class;

if(OTP::getStatus()){
    return OTP::getMessage();
}

return OTP::getAccessToken();
return OTP::getIpAddress();



use Larakeeps\AuthGuard\Facades\OTP;



/** 
 * 
 * Method to check if the generated code exists.
 * $phone parameter is used for better code verification assertiveness.
 * 
 * @method static bool hasCode(string $code, string|null $phone)
 * 
 * */

$hasCode = OTP::hasCode('154896');

if($hasCode){
    return "The code exist."
}


/** 
 * 
 * Method for finding and returning data.
 * $phone parameter is used for better code verification assertiveness.
 * 
 * @method static OTP getByCode(string $code, string|null $phone)
 * 
 * */

$authGuardFounded = OTP::getByCode('154896', '5521985642205');

if($authGuardFounded){
    return $authGuardFounded
}



use Larakeeps\AuthGuard\Facades\OTP;


/** 
 * 
 * The create method has 3 parameters, 2 mandatory and 1 optional.
 * 
 * The $reference parameter is used with the assertive condition function in code validation.
 * 
 * @param string $code : rieve the method return, call the following methods below.

/** 
 * 
 * The then method returns 2 parameters, $data of type AuthGuard, and $response of type Collection.
 * 
 * @method then(Closure $destination)
 * 
 * */
 
$validateCode->then(function (null $data, Collection $response){
       
       /*
        * 
        * Within the confirm() method, the $data parameter will always return a null value.
        * 
        * The $response parameter returns a collection containing the following data: 
        * number_digits, code, message, status, user.access_token, user.ip_address
        */
        
        if($response->status && OTP::isConfirmed()){
            return $response->message;
        }
        
        return $response->message;
       
});

// OR through the getResponse() method that returns a Collection

return $createOTP->getResponse();

// OR like this

return OTP::getResponse();

// OR can be called individually using methods

if(OTP::getStatus()){
    return OTP::getMessage();
}

return OTP::getAccessToken();
return OTP::getIpAddress();



use Larakeeps\AuthGuard\Facades\OTP;

/** 
 * 
 * @method OTP deleteCode(string $code)
 * 
 * */
 
$deletedCode = OTP::deleteCode();

// To retrieve the method return, call the following methods below.

/** 
 * 
 * The then method returns 2 parameters, $data of type AuthGuard, and $response of type Collection.
 * 
 * @method then(Closure $destination)
 * 
 * */
 
$validateCode->then(function (null $data, Collection $response){
       
       /*
        * 
        * Within the deleteCode() method, the $data parameter will always return a null value.
        * 
        * The $response parameter returns a collection containing the following data: 
        * number_digits, code, message, status, user.access_token, user.ip_address
        */
        
        if($response->status){
            return $response->message;
        }
       
});

// OR through the getResponse() method that returns a Collection

return $createOTP->getResponse();

// OR like this

return OTP::getResponse();

// OR can be called individually using methods

if(OTP::getStatus()){
    return OTP::getMessage();
}

return OTP::getAccessToken();
return OTP::getIpAddress();


shell script
php artisan migrate
shell script
php artisan vendor:publish --tag=authguard-otp-config