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 Notification Log Laravel Package

spatie/laravel-notification-log

Logs all notifications sent by your Laravel app, storing them as NotificationLogItems so you can query what was sent to a user, display notification history, and make sending decisions (e.g., avoid duplicates) via helpers like wasSentTo() and inThePastMinutes().

View on GitHub
Deep Wiki
Context7

title: Working with fingerprints weight: 3

Notification typically accept parameters in the constructor that will be used to determine the message of the notification.

use Illuminate\Notifications\Notification;

class OrderSentNotification extends Notification
{
    public function __construct(
        public Order $order,
    ) {}

To log that a notification was sent for a set of constructor parameters, you can add a fingerprint. A fingerprint is a simple string that will be logged along with the sent notification.

To add a signature to a notification, add a function fingerprint to your notification.

use Illuminate\Notifications\Notification;

class OrderSentNotification extends Notification
{
    public function __construct(
        public Order $order,
    ) {}
    
    public function fingerprint()
    {
        return "order-{$this->order->id}";
    }
}

The fingerprint will be saved in the fingerprint on the log item that is created when the notification is sent.

// returns the fingerprint
Spatie\NotificationLog\Models\NotificationLogItem::first()->fingerprint;

You can use the fingerprint to hunt down notifications using the latestFor method.

// return the latest logged notification for the first order.

$logItem = NotificationLogItem::latestFor($notifiable, fingerprint: "order-1");

When your notification has a lot, or complex, constructor parameters, you could use a hashing function like md5 to generate a value that is unique for those parameters.

use Illuminate\Notifications\Notification;

class OrderSentNotification extends Notification
{
    public function __construct(
        public string $parameter,
        public string $anotherParameter,
        public string $yetAnotherOne,

    ) {}
    
    public function fingerprint()
    {
        return md5("{$this-parameter}-{$this->anotherParameter}-{$yetAnotherOne}";
    }
}
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