Weave Code
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 One Time Passwords Laravel Package

spatie/laravel-one-time-passwords

Generate and verify secure one-time passwords (6‑digit by default) in Laravel. Sends OTPs via mail notifications (extendable to SMS/other channels) and includes a Livewire login component. Optional Flux support provides an enhanced OTP input UI.

View on GitHub
Deep Wiki
Context7

title: Configuring notifications weight: 3

The package uses the included OneTimePasswordNotification notification to mail one-time passwords to users.

By extending the notification, you can send the one-time password via other channels, such as SMS or Slack.

You can extend this notification to customize the content and appearance of the email.

Adding support for additional channels

To add support for additional channels, you can do so by creating a new notification class that extends the Spatie\OneTimePasswords\Notifications\OneTimePasswordNotification class. In that custom class, you can add additional channels to the via method.

Before adding support for additional channels, please make sure to read the Laravel documentation on customizing notification channels.

Here's an example of how to add support for SMS (via Vonage as explained in the Laravel docs).

namespace App\Notifications;

use Spatie\OneTimePasswords\Notifications\OneTimePasswordNotification;

class CustomOneTimePasswordNotification extends OneTimePasswordNotification
{
    public function via($notifiable): string|array
    {
        return ['vonage'];
    }

    public function toVonage(object $notifiable): VonageMessage
    {
        // $this->oneTimePassword is an instance of the Spatie\OneTimePasswords\OneTimePassword model
    
        return (new VonageMessage)
            ->content("Your one-time login code is: {$this->oneTimePassword->password}");
    }
}

To complete the SMS routing, don't forget to add the routeNotificationForVonage to your User model (as explained in the Laravel docs).

namespace App\Models;
 
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Notifications\Notification;
 
class User extends Authenticatable
{
    use Notifiable;
 
    /**
     * Route notifications for the Vonage channel.
     */
    public function routeNotificationForVonage(Notification $notification): string
    {
        return $this->phone_number;
    }
}

Finally, you need to update the config/one-time-passwords.php configuration file to use your custom notification class.

// config/one-time passwords.php

return [
    // ...
    'notification' => App\Notifications\CustomOneTimePasswordNotification::class
];

Styling the mail notification

The easiest way to customize the looks of the mail notification is by publishing the views.

php artisan vendor:publish --tag=one-time-passwords-views

This will publish the views to resources/views/vendor/one-time-passwords/mail.blade.php. You can customize this view to change the appearance of the notification.

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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai