PHP code example of putheakhem / laravel-otp

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

    

putheakhem / laravel-otp example snippets


return [
    'length' => 6, // OTP length
    'expires_in' => 300, // OTP expiration time in seconds (5 minutes)
    'max_attempts' => 5, // Maximum failed attempts before invalidation
    'lock_to_session' => true, // OTP tied to user session
    'mail_template' => 'otp::emails.otp', // Email template for OTP
    'logging_enabled' => true, // Enable OTP logging
];

use PutheaKhem\Otp\Facades\Otp;

$otp = Otp::generate('[email protected]');

dd($otp);

PutheaKhem\Otp\Models\Otp {#123
  id: 1,
  identifier: "[email protected]",
  otp: "123456",
  used: false,
  attempts: 0,
  expires_at: "2025-02-10 12:00:00"
}

$response = Otp::validate('[email protected]', '123456');

dd($response);
sh
php artisan vendor:publish --provider="PutheaKhem\Otp\Providers\OtpServiceProvider"
php artisan migrate

resources/views/vendor/otp/emails/otp.blade.php
sh
php artisan test