PHP code example of zebrains / laravel-data-verificator

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

    

zebrains / laravel-data-verificator example snippets


php artisan migrate

php artisan vendor:publish --provider="Zebrains\LaravelDataLocker\OtpServiceProvider" --tag="config"



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Prozorov\DataVerification\Types\Address;

class OtpController extends Controller
{
    /**
     * Handle the incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function __invoke(Request $request)
    {
        $manager = app('otp');

        $address = new Address('79034106060');

        $otp = $manager->generateAndSend($address, 'sms');

        return response()->json(['code' => $otp->getVerificationCode()]);
    }
}



namespace App\Http\Controllers;

use Illuminate\Http\Request;

class VerificationController extends Controller
{
    /**
     * Handle the incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function __invoke(Request $request)
    {
        $manager = app('otp');

        $pass = $request->get('pass');
        $code = $request->get('code');

        $otp = $manager->verifyOrFail($code, $pass);
    }
}



namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Zebrains\LaravelDataLocker\HandlesOtpExceptions;
use Throwable;

class Handler extends ExceptionHandler
{
    use HandlesOtpExceptions;

    protected $dontFlash = [
        'password',
        'password_confirmation',
    ];

    public function register()
    {
        $this->reportable(function (Throwable $e) {
            //
        });

        $this->registerOtpExceptionHandlers();
    }
}



namespace App\Providers;

use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;
use Prozorov\DataVerification\Events\OtpGenerationEvent;

class EventServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Event::listen(function (OtpGenerationEvent $event) {
            if ((string) $event->getAddress() === '79181234567') {
                $event->setOtp('1234');
            }
        });
    }
}


php artisan otp:clear