• Reading time ~ 1 min
  • 03.03.2023

Laravel Notification Log is a package by Spatie to log notifications your Laravel app sends. This will allow you to query notification logs in the database for your app users:

// returns a collection of `NotificationLogItem` models
$sentNotifications = $user->loggedNotifications();

You can customize which notifications get logged, and by default, all notifications are logged. Each notification can have custom logic by defining a shouldLog method to determine if the notification should get logged:

use Illuminate\Notifications\Events\NotificationSending;

// in a notification
public function shouldLog(NotificationSending $event): bool
{
    // i.e., custom logic to decide if a notification
    // should get logged...
    return true;
}

Using this package, you can also query all logged notifications using a provided Eloquent model. This package offers additional customization options such as logging extra notification data, defining a notification fingerprint signature, and more. You can learn about all the options in the official documentation.

If you'd like to learn more, check out the source code on GitHub at spatie/laravel-notification-log and read Log all notifications sent by your Laravel app by Freek Van der Herten.

Comments

No comments yet
Yurij Finiv

Yurij Finiv

Full stack

ABOUT

Professional Fullstack Developer with extensive experience in website and desktop application development. Proficient in a wide range of tools and technologies, including Bootstrap, Tailwind, HTML5, CSS3, PUG, JavaScript, Alpine.js, jQuery, PHP, MODX, and Node.js. Skilled in website development using Symfony, MODX, and Laravel. Experience: Contributed to the development and translation of MODX3 i...

About author CrazyBoy49z
WORK EXPERIENCE
Contact
Ukraine, Lutsk
+380979856297