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: Installation & setup weight: 4

You can install the package via composer:

composer require spatie/laravel-notification-log

You can publish and run the migrations with:

php artisan vendor:publish --tag="notification-log-migrations"
php artisan migrate

Publishing the config file

Optionally, you can publish the config file with:

php artisan vendor:publish --tag="notification-log-config"

This is the contents of the published config file:

return [
    /*
     * This model will be used to log all sent notifications
     */
    'model' => Spatie\NotificationLog\Models\NotificationLogItem::class,

    /*
     * Log items older than this number of days will be automatically be removed.
     *
     * This feature uses Laravel's native pruning feature:
     * https://laravel.com/docs/12.x/eloquent#pruning-models
     */
    'prune_after_days' => 30,

    /*
     * If this is set to true, any notification that does not have a
     * `shouldLog` method will be logged.
     */
    'log_all_by_default' => config('notification-log.log_all_by_default'),

    /*
     * By overriding these actions, you can make low level customizations. You can replace
     * these classes by a class of your own that extends the original.
     *
     */
    'actions' => [
        'convertEventToModel' => Spatie\NotificationLog\Actions\ConvertNotificationSendingEventToLogItemAction::class
    ],

    /*
     * The event subscriber that will listen for the notification events fire by Laravel.
     * In most cases, you don't need to touch this. You could replace this by
     * a class of your own that extends the original.
     */
    'event_subscriber' => Spatie\NotificationLog\NotificationEventSubscriber::class,
];

Pruning results

This package will store all sent notifications in the notification_log_items table. The related NotificationLogItems models uses the Laravel's MassPrunable trait. In the notification-log config file, you can specify the maximum age of a model in the prune_after_days key. Don't forget to schedule the model:prune command, as instructed in Laravel's docs. You'll have to explicitly add the model class:

Laravel 11+

// in routes/console.php

use Illuminate\Support\Facades\Schedule;

Schedule::command('model:prune', [
    '--model' => [
        \Spatie\NotificationLog\Models\NotificationLogItem::class,
    ],
])->daily();

Laravel 10

// in app/Console/Kernel.php

class Kernel extends ConsoleKernel
{
    protected function schedule(Schedule $schedule)
    {
         $schedule->command('model:prune', [
                    '--model' => [
                        \Spatie\NotificationLog\Models\NotificationLogItem::class,
                    ],
        ])->daily();
    
        // ...   
    }
}
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
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
uri-template/tests