PHP code example of codedive-io / laravel-code-verification

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

    

codedive-io / laravel-code-verification example snippets


use Codedive\LaravelCodeVerification\CodeVerificationService;

$service = app(CodeVerificationService::class);

$verificationCode = $service->issue(
    $receiver = '[email protected]',
    $purpose = 'verify_email',
    $userId = 1
)

use Codedive\LaravelCodeVerification\CodeVerification;

CodeVerification::issue(
    $receiver = '[email protected]',
    $purpose = 'verify_email',
    $userId = 1
);

use Codedive\LaravelCodeVerification\CodeVerificationService;

$service = app(CodeVerificationService::class);

$isVerified = $service->verify(
    $receiver = '[email protected]',
    $purpose = 'verify_email',
    $user_id = 1,
    $code = '123456'
);

if ($isVerified) {
    // The code was successfully verified
} else {
    // Code verification failed
}

use Codedive\LaravelCodeVerification\CodeVerification;

$isVerified = CodeVerification::verify(
    $receiver = '[email protected]',
    $purpose = 'verify_email',
    $user_id = 1,
    $code = '123456'
);

return [
    'code_length' => 6,     // Length of the generated code
    'expires_in' => 300,    // Code expiration time (in seconds)
    'max_attempts' => 3,    // Maximum number of attempts
];
bash
php artisan migrate
bash
php artisan vendor:publish --tag=code-verification-config