PHP code example of cuongnx / laravel-flexible-otp
1. Go to this page and download the library: Download cuongnx/laravel-flexible-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/ */
cuongnx / laravel-flexible-otp example snippets
'model' => App\\Models\\OtpRecord::class, // or the name you chose
use Cuongnx\\LaravelFlexibleOtp\\Facades\\Otp;
// Generate OTP normal (returns plain token, does not send)
$response = Otp::generate('+84123456789');
// Generate OTP with purpose (returns plain token, does not send)
$response = Otp::generate('+84123456789', purpose: 'verify_phone');
// Generate and automatically send the OTP
$response = Otp::generate(
'+84123456789',
purpose: 'verify_phone',
send: true,
provider: 'zalo_zns' // or 'speedsms', 'mail'
);
// Validate OTP
$result = Otp::validate('+84123456789', '123456', purpose: 'verify_phone');
if ($result->status) {
// OTP is valid
}
// Check validity without consuming
$isValid = Otp::isValid('+84123456789', '123456', purpose: 'verify_phone');