Download the PHP package sadiqsalau/laravel-otp without Composer
On this page you can find all versions of the php package sadiqsalau/laravel-otp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-otp
Laravel OTP
Introduction
OTP Package for Laravel using class based system. Every Otp is a class that does something. For example, an EmailVerificationOtp
which will mark the account as verified.
Installation
Install via composer
Publish config file
Usage
Generate OTP
A new Otp class will be generated into the app/Otp
directory. e.g
Every Otp must implement the process
method which will be called after verification. There the Otp can perform the necessary action and return any result.
Sending OTP
$otp
: The otp to send.$notifiable
: AnonymousNotifiable or Notifiable instance.
Returns
Verify OTP
$code
: The otp code to compare against.
Returns
The result
key contains the returned value of the process
method of the Otp class
Verify OTP without clearing from cache
$code
: The otp code to compare against.
Returns
Resend OTP
Returns
Setting Identifier
Every method of the OTP class requires setting an identifier to uniquely identify the Otp.
Config
Config file can be found at config/otp.php
after publishing the package
format
- Format of generated OTP code (numeric
|alphanumeric
|alpha
)length
- Length of generated OTP codeexpires
- Number of minutes before OTP expires,notification
- Custom notification class to use, default isSadiqSalau\LaravelOtp\OtpNotification
Translations
The package doesn't provide translations out of the box, but here is an example.
Create a new translation file: lang/en/otp.php
Then translate the status
API
-
Otp::identifier(mixed $identifier)
- Set OTP identifier -
Otp::send(OtpInterface $otp, mixed $notifiable)
- Send OTP to a notifiable -
Otp::attempt(string $code)
- Attempt OTP code, returns the result of calling theprocess
method of the OTP -
Otp::check(string $code)
- Compares the code against current OTP, this doesn't process or clear the OTP -
Otp::update()
- Resend and update current OTP -
Otp::clear()
- Remove OTP -
Otp::useGenerator(callable $callback)
- Set custom generator to use, generator will be called with$format
and$length
Otp::generateOtpCode($format, $length)
- Generates the OTP code
Contribution
Contributions are welcomed.