PHP code example of itsmurumba / laravel-otp

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

    

itsmurumba / laravel-otp example snippets


use Itsmurumba\Otp\Facades\Otp;

// Generate and send an OTP (defaults to the "sms" channel)
$otp = Otp::generateAndSend('[email protected]', 'email');

// Verify an OTP
$isValid = Otp::verify('[email protected]', $otp);

$otpService = otp(); // same as app('otp')

$otp = $otpService->length(6)
    ->expiresIn(10)
    ->rateLimit(3, 15)
    ->generateAndSend('[email protected]', 'email');

$isValid = $otpService->verify('[email protected]', $otp);

use Itsmurumba\Otp\Channels\EmailChannel;

$channel = new EmailChannel();
$result = $channel->send('[email protected]', '123456');

use Itsmurumba\Otp\Channels\SmsChannel;

$channel = new SmsChannel();
$result = $channel->send('+1234567890', '123456');

use Itsmurumba\Otp\Channels\WhatsAppChannel;

$channel = new WhatsAppChannel();
$result = $channel->send('+1234567890', '123456');

use Itsmurumba\Otp\Channels\TelegramChannel;

$channel = new TelegramChannel();
$result = $channel->send('chat_id', '123456');

use Itsmurumba\Otp\Channels\SlackChannel;

$channel = new SlackChannel();
$result = $channel->send('#channel-name', '123456');

$otp = $otpService->generateAndSend('+1234567890', ['sms', 'whatsapp']);

$isValid = $otpService->verify('+1234567890', $otp);
bash
php artisan vendor:publish --provider="Itsmurumba\Otp\OtpServiceProvider"