Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Otp

Laravel Otp Laravel Package

teckwei1993/laravel-otp

A Laravel package for generating, sending, and verifying one-time passwords (OTPs). It supports configurable code length, expiry, resend limits, and custom delivery channels, making it easy to add secure OTP verification to login, registration, or sensitive actions.

View on GitHub
Deep Wiki
Context7

A package for Laravel One Time Password (OTP) generator and validation without Eloquent Model, since it done by Cache.

Frequently asked questions about Laravel Otp
How do I install teckwei1993/laravel-otp in a Laravel application?
Install it with Composer using composer require teckwei1993/laravel-otp. Laravel's package auto-discovery registers the service provider, so you normally do not need to add anything to the providers array by hand. After installing, publish the package config file so you can set code length, expiry, resend limits and your delivery channel. Check the composer.json constraints first to confirm the release you are pulling supports your Laravel and PHP versions.
Does laravel-otp need a database table or an Eloquent model?
No. The package keeps OTP codes in Laravel's cache instead of an Eloquent model, so there are no migrations to run and no new tables to maintain. The trade-off is that a code only lives as long as its cache entry, so clearing the cache invalidates any pending OTPs. Use a shared, persistent cache store such as Redis or Memcached in production so every app server sees the same code.
How do I configure OTP code length, expiry time and resend limits?
After publishing the config file you can set the number of digits in the code, the expiry window, and the resend cooldown that throttles repeat requests for the same identifier. Keep the expiry short, a few minutes at most, and set a resend limit that blocks SMS-pumping abuse where an attacker triggers paid messages repeatedly. Because the expiry is enforced through the cache entry's lifetime, config changes apply to newly generated codes rather than ones already issued.
How do I send the OTP by SMS or email instead of using a built-in channel?
The package separates code generation from delivery, so you supply the sending logic and wire it into the package config; the OTP itself is generated and cached for you. That keeps you free to use Twilio, Vonage, AWS SNS, a Laravel notification, or plain Mail without changing the verification flow. If your provider is slow or rate limited, queue the send so the request that triggers the OTP still returns quickly. Always send the code out-of-band and never echo it back in the API response.
Which Laravel versions does this package support, and is Laravel 13 really supported?
The only published compatibility evidence is the v1.0.14 changelog line stating support for Laravel 13. That confirms a widened framework constraint, but a one-line changelog does not prove the service provider, config merging and container bindings were actually exercised against Laravel 13. Read composer.json for the exact laravel/framework and PHP floors, and confirm your current Laravel 11 or 12 application is still inside the supported range before upgrading. If you need certainty for production, run a smoke test on the target version or open an issue asking whether the support is CI-verified.
How do I verify a submitted OTP code and handle wrong or expired codes?
You generate a code, deliver it to the user, then call the package's validation method with the same identifier (email or phone) plus the code the user submitted. It compares the input against the cached value and reports whether it matched, and it can consume the code on success so it cannot be replayed. Handle the failure paths in your own controller: return a generic invalid-or-expired message, rate limit verification attempts per identifier and per IP, and log repeated failures for abuse detection.
Which cache driver should I use for OTPs in production?
Use a shared, persistent store such as Redis or Memcached rather than the array driver, and avoid the file driver if you run more than one server. The code is written on one request and read back on another, possibly on a different instance, so it must be visible cluster-wide. Give the cache a unique key prefix per environment so staging codes can never validate in production, and avoid blanket cache flushes during deploys while OTPs are outstanding.
How do I test OTP flows with PHPUnit or Pest without sending real messages?
Replace the delivery channel with a fake in your test suite so no SMS or email leaves the application, and assert against the code the package generated. Running tests on the array cache driver keeps each test isolated, fast and free of stale codes. Cover the unhappy paths as well: expired code, resend cooldown exceeded, too many verification attempts, and reuse of a code that was already consumed.
What are the alternatives to laravel-otp for adding OTP verification to Laravel?
Alternatives include a small hand-rolled solution using Cache::put plus a hash_equals comparison, Laravel signed URLs for email-based confirmation links, or larger packages that ship Eloquent-backed tokens, notifications and built-in rate limiting. Choose this package when you want a lightweight, cache-only helper with no migrations and a pluggable sender. Choose a heavier package when you need audit trails, per-user token history, or multi-channel delivery out of the box, and weigh the maintenance signal either way.
Is teckwei1993/laravel-otp actively maintained and safe for production?
The scope is small and low-risk, but the evidence base is thin: the repository shows a single-line changelog for the Laravel 13 release, with no published test results, upgrade guide or changelog detail beyond that. The main production risks are silent incompatibility from a widened constraint that was not tested, and cache misconfiguration across multiple servers. Pin the exact version in composer.json, run a smoke test against your Laravel and PHP versions, and have a fallback plan in case the package stops tracking framework releases.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings
coleus/apps
seampact/laravel
emmyconceptng/laravel-ng-postcode
jjsquady/round-robin
skyraptor/chatter
edlugz/sasapay
abbasudo/artisan-route