PHP code example of ars / laravel-otp-code

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

    

ars / laravel-otp-code example snippets


$otpRepository = new \Ars\Otp\Repositories\OtpRepository();
$otp = $otpRepository->create('[email protected]');
$code = $otp->code;

$isValid = $otpRepository->verify('[email protected]', 1234);

$exists = $otpRepository->has('[email protected]');

use Ars\Otp\Facades\OtpCode;

// Create OTP
$otp = OtpCode::create('[email protected]');
$code = $otp->code;
// Verify OTP
$isValid = OtpCode::verify('[email protected]', 1234);

use Ars\Otp\Rules\OtpCode;

$request->validate([
    'email' => '[email protected]',
    'otp_code' => ['

use Ars\Otp\Facades\OtpCode;

    //If has salt send parameter after identifier
    public function sendOtp($email, $salt = null)
    {
        if (OtpCode::has($email, $salt)) {
            return Responder::setErrorCode(201)->setMessage(trans('otp_code::otp-code.already_send'))->respond();
        }

        $otp = OtpCode::create($email, $salt);

        Notification::send($email, new OtpNotification($otp->code));
    }

bash
   php artisan vendor:publish --provider="Ars\Otp\Providers\OtpCodeServiceProvider"
   
bash
   php artisan migrate
   
bash
php artisan vendor:publish --tag=lang --provider="Ars\Otp\Providers\OtpCodeServiceProvider"
bash
php artisan otp:clear-expired