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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation