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 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.
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin
artisan-build/community-prompts
vleroy/smart
ayles-software/laravel-australian-public-holidays
cboxdk/laravel-id-spatie
cboxdk/laravel-id-billing
cboxdk/laravel-id-billing-bridge
simple-as-fuck/php-performance-log
hsluv/hsluv
seampact/codegen
seampact/hooks
seampact/ir
mehedimi/laravel-amp-mail
happones/laravel-vue-i18n-generator
jwerd/inertia-table