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().
NotificationSent events). This aligns well with modern Laravel architectures that use events, queues, or observers for side effects.composer require and minimal configuration.notification_logs table, requiring a migration. Compatible with Eloquent models, but may need schema adjustments for complex use cases (e.g., soft deletes, archiving).toMail, toArray, etc., are properly defined for accurate logging.recent(), failed()) or TTL policies.NotificationLog model or create a separate table.NotificationFake or mock the logger.user_id, campaign_id) needed beyond the default log structure?queue:work for async notifications.NotificationFake for unit/feature tests.timestamps and softDeletes are compatible.toArray()/toMail() methods.Log::channel()?).composer require spatie/laravel-notification-log
php artisan vendor:publish --provider="Spatie\NotificationLog\NotificationLogServiceProvider"
php artisan migrate
config/notification-log.php (e.g., log channels, table name).NotificationLog model if additional fields are needed.UserSentPasswordResetNotification).via() and to* methods are implemented.Notification::route() or custom event listeners).LogNotification job).NotificationLog model or table.$failedLogs = NotificationLog::where('exception', '!=', null)->latest()->get();
NotificationLog::forUser($user)).user_id, notifiable_type).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Database downtime | Logs lost during outage. | Use a queue + retry logic for logging. |
| Unhandled notification exceptions | Logs may not capture full context. | Wrap Notification::send() in a try-catch and log exceptions manually. |
| Log table bloat | Slow queries, storage costs. | Set TTL policies or archive old logs. |
| Custom channel failures (e.g., S3) | Logs not persisted. | Implement fallback to DB logging or alert on channel failures. |
| Laravel queue failures | Async logs delayed/failed. | Monitor queue backlogs; implement dead-letter queues for failed log jobs. |
sent_at to a custom field).How can I help you explore Laravel packages today?