Download the PHP package cuongnx/laravel-flexible-otp without Composer
On this page you can find all versions of the php package cuongnx/laravel-flexible-otp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cuongnx/laravel-flexible-otp
More information about cuongnx/laravel-flexible-otp
Files in cuongnx/laravel-flexible-otp
Package laravel-flexible-otp
Short Description A flexible OTP (One-Time Password) library for Laravel, supporting multi-purpose configurations, multi-storage (MongoDB/MySQL), resend cooldown, hashing for security, and optional sending via providers like Zalo ZNS, SpeedSMS, or mail.
License MIT
Informations about the package laravel-flexible-otp
cuongnx/laravel-flexible-otp
A powerful and highly flexible One-Time Password (OTP) package for Laravel applications.
✨ Key Features
- Multi-purpose configuration – Define separate OTP settings for different use cases (login, phone verification, password reset, etc.).
- Multi-storage support – Works seamlessly with MySQL or MongoDB.
- Per-purpose cooldown & rate limiting – Prevent abuse with fine-grained control.
- Optional automatic sending – Built-in support for Zalo ZNS, SpeedSMS, Mail, or any custom provider.
- Modern PHP 8+ named arguments – Clean, readable, and type-safe API.
📦 Requirements
- PHP ^8.2
- Laravel ^11.0 or ^12.0
🚀 Installation
The package auto-registers its service provider and facade.
⚙️ Configuration
Publish the configuration file (recommended):
This will create:
🧩 Create the OTP Model
The package supports both MySQL and MongoDB.
Generate the appropriate model:
- If
connectionis set tomongodb→ the model extendsMongoDB\\Laravel\\Eloquent\\Model - Otherwise → the model extends
Illuminate\\Database\\Eloquent\\Model
After generation, update the config:
🗄 Migration
A migration is included and automatically published. Run:
This creates the one_time_passwords table or collection.
🛠 Usage
🧾 Example Configuration (config/otp.php)
📩 Automatic OTP Sending
When send: true is passed, the package dispatches an OtpGenerated event.
Create a listener to handle sending:
Then implement your sending logic inside the handle method.
Quick Start: Generate Ready-to-Use Listener
The package provides a convenient command to create a complete listener with pre-built support for popular providers:
This command generates app/Listeners/SendOtpListener.php with ready-to-use code for:
- SpeedSMS
- Zalo ZNS
You can also specify a custom name:
🧹 Cleaning Expired OTPs
Manually clean expired OTPs:
Recommended: schedule it in app/Console/Kernel.php:
📄 License
MIT License – see the LICENSE file for details.
cuongnx/laravel-flexible-otp – A flexible, secure, and developer-friendly OTP solution for modern Laravel projects.