PHP code example of digitaltunnel / otakit

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

    

digitaltunnel / otakit example snippets


    use DigitalTunnel\OtaKit\Traits\Otakit;
    
    class User extends Model
    {
        use Otakit;
    }

    use App\Models\User;

    $user = User::find(1);
    $otp = $user->generateOtp();

    $otp = $user->generateOtp(length: 6, ttl: 10);

    use App\Models\Customer;
    use DigitalTunnel\Otakit\Actions\GenerateOtp;
    
    $otpable = Customer::find(1);
    
    $otp = (new GenerateOtp)->handle(
        otpable :$otpable,
        length :4,
        ttl: 5 // Time to live in minutes
    )

    use App\Models\User;

    $user = User::find(1);
    $isValid = $user->validateOtp(
        otp: 123456
    );

    use App\Models\Customer;
    use DigitalTunnel\Otakit\Actions\ValidateOtp;
    
    $otpable = Customer::find(1);
    
    $isValid = (new ValidateOtp)->handle(
        otpable :$otpable,
        otp: 123456
    )

    protected $listen = [
        OtpGenerated::class => [
            // you listeners
            // send otp though sms or email or any other channel
            // log the otp generated
            // etc...
        ],
        
        OtpValidationSuccess::class => [
            // you listeners
            // log the otp validation success
            // etc...
        ],
        
        OtpValidationFailed::class => [
            // you listeners
            // log the otp validation failed
            // etc...
        ],
    ];
bash
php artisan vendor:publish --provider="DigitalTunnel\Otakit\Providers\OtakitServiceProvider"