Looking to hire Laravel developers? Try LaraJobs

laravel-otp maintained by elysiumrealms

Description
A package to generate and validate OTP
Author
Last update
2025/03/08 14:52 (dev-master)
License
Downloads
391

Comments
comments powered by Disqus

OTP Verification System

A module for generating and verifying OTPs.

Installation Guide

Install the package using Composer.

composer require elysiumrealms/laravel-otp

Publish the assets.

php artisan vendor:publish --tag=otp-assets

Run the migrations.

php artisan migrate

Implementation Guide

Schedule the otp:clean command to clean expired OTPs.

function schedule(Schedule $schedule)
{
    $schedule->command('otp:clean')
        ->onOneServer()
        ->everyFiveMinutes();
}

Usage Guide

Generate an for a mobile number.

curl -X POST http://localhost:8000/api/v1/otp/sms/generate \
    -H "Content-Type: application/json"
    -d '{"identifier": "1234567890"}'

Generate an OTP for an email address.

curl -X POST http://localhost:8000/api/v1/otp/mail/generate \
    -H "Content-Type: application/json"
    -d '{"identifier": "test@example.com"}'

Verify an OTP.

curl -X POST http://localhost:8000/api/v1/otp/validate \
    -H "Content-Type: application/json"
    -d '{"identifier": "1234567890", "token": "123456"}'

Verify an OTP for an email address.

curl -X POST http://localhost:8000/api/v1/otp/email/validate \
    -H "Content-Type: application/json"
    -d '{"identifier": "test@example.com", "token": "123456"}'

Check if identifier is verified with validator.

public function __invoke(Request $request)
{
    $request->validate([
        'identifier' => 'required|otp_verified',
    ]);
}

Check if identifier is verified.

if (\Elysiumrealms\Otp\Facades\Otp::verified('1234567890'))
    echo 'Identifier is verified';

For further details, please contact the development team.