PHP code example of youngmayor / laravel-otp

1. Go to this page and download the library: Download youngmayor/laravel-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/ */

    

youngmayor / laravel-otp example snippets


'providers' => [
    // ...
    YoungMayor\LaravelOtp\LaravelOtpServiceProvider,
    // ...
],

// ...
use YoungMayor\LaravelOtp\Traits\OTPActions;
// ...

class ExampleModel
{
    // ...
    use OTPActions;
    // ....
}
 
> class ExampleModel
> {
>   use OTPActions; 
>
>   public $otpEmailKey = 'user_email';
> }
> 
 
// $exampleModel is an instance of ExampleModel
// $payload is additional data that you would like to attach to the OTP token. 
// The payload can be an array, a string or an integer
$exampleModel->generatOTP('action-name', $payload);
 
// $exampleModel is an instance of ExampleModel and has a pending OTP
// $pin is the OTP pin that is to be validated
$otp = $exampleModel->validateOTP($pin, 'action-name');
 
if (!$otp) {
    // handle invalid OTP code
}
 
$otp->is_expired; // check if the OTP is expired

$payload = $otp->payload; // retrieve the OTP's Payload

$otp->refreshOTP(); // re-generate a new OTP code and send to the recipient

$otp->delete(); // delete the OTP
 
$exampleModel = $otp->source;
bash
php artisan vendor:publish --provider="YoungMayor\LaravelOtp\LaravelOtpServiceProvider" 
bash
php artisan migrate