PHP code example of kenkioko / laravel-otp

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

    

kenkioko / laravel-otp example snippets



   /*
    |--------------------------------------------------------------------------
    | Autoloaded Service Providers
    |--------------------------------------------------------------------------
    |
    | The service providers listed here will be automatically loaded on the
    | request to your application. Feel free to add your own services to
    | this array to grant expanded functionality to your applications.
    |
    */

    'providers' => [
        ...
        Kenkioko\OTP\OTPServiceProvider::class,
    ];
...



   /*
    |--------------------------------------------------------------------------
    | Class Aliases
    |--------------------------------------------------------------------------
    |
    | This array of class aliases will be registered when this application
    | is started. However, feel free to register as many as you wish as
    | the aliases are "lazy" loaded so they don't hinder performance.
    |
    */

    'aliases' => [
        ...
        'OTP' => Kenkioko\OTP\OTP::class,
    ];
...



OTP::generate(App\User $identifier, int $digits = 4, int $validity = 5)



$user = App\User::find(1);
$otp = OTP::generate($user, 6, 15);



OTP::validate(App\User $identifier, string $token)



$user = App\User::find(1);
$otp = OTP::generate($user, '282581');



OTP::extend(App\User $identifier, string $token, int $validity = 1)



$user = App\User::find(1);
$otp = OTP::extend($user, '282581', 5);
bash
php artisan vendor:publish --provider="Kenkioko\OTP\OTPServiceProvider"
bash
php artisan migrate