PHP code example of salehhashemi / laravel-otp-manager
1. Go to this page and download the library: Download salehhashemi/laravel-otp-manager 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/ */
salehhashemi / laravel-otp-manager example snippets
use Salehhashemi\OtpManager\Facade\OtpManager;
$sentOtp = OtpManager::send("1234567890");
use Salehhashemi\OtpManager\Events\OtpPrepared;
class SendOtpNotification
{
public function handle(OtpPrepared $event)
{
$mobile = $event->mobile;
$otpCode = $event->code;
// Send the OTP code to the mobile number
// You can use your preferred SMS service here.
}
}
use Salehhashemi\OtpManager\Contracts\OtpTypeInterface;
enum MyOtpEnum: string implements OtpTypeInterface
{
case SIGNUP = 'signup';
case RESET_PASSWORD = 'reset_password';
public function identifier(): string
{
return $this->value;
}
}
Route::middleware('otp-rate-limiter')->group(function () {
// Routes that
use Salehhashemi\OtpManager\Contracts\MobileValidatorInterface;
class CustomMobileValidator implements MobileValidatorInterface
{
public function validate(string $mobile): void
{
// Your validation logic here
}
}