pharaonic / laravel-notification-dependencies
Attach Laravel database notifications to Eloquent models and delete them automatically when any of those models is deleted.
Package info
github.com/Pharaonic/laravel-notification-dependencies
pkg:composer/pharaonic/laravel-notification-dependencies
Requires
- php: >=8.3 <8.6
- illuminate/contracts: ^13.0
- illuminate/database: ^13.0
- illuminate/notifications: ^13.0
- illuminate/support: ^13.0
Requires (Dev)
- laravel/pint: ^1.20
- orchestra/testbench: ^11.0
- pestphp/pest: ^4.0
- phpstan/phpstan: ^2.1.33
- phpunit/phpunit: ^12.5.8
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-07 05:04:59 UTC
README
Keep database notifications relevant: attach them to Eloquent models and delete them as soon as any of those models is deleted.
The 13.x line supports Laravel 13 on PHP 8.3, 8.4 and 8.5.
Installation
The package links rows of Laravel's own notifications table, so that table has to exist first:
# Only if the application has no notifications table yet:
php artisan notifications:table
php artisan migrate
composer require pharaonic/laravel-notification-dependencies:^13.0
php artisan migrate
The service provider is registered automatically, and migrate creates the notification_dependencies table. Publish the configuration when you need to change it:
php artisan vendor:publish --tag=notification-dependencies-config
Usage
Add HasDependentNotifications to the models a notification can depend on, and HasDependencies to the notification. The notification is deleted as soon as any of its dependencies is deleted:
use Pharaonic\Laravel\NotificationDependencies\Concerns\HasDependencies; use Pharaonic\Laravel\NotificationDependencies\Concerns\HasDependentNotifications; class Order extends Model { use HasDependentNotifications; } class OrderCommented extends Notification { use HasDependencies; public function via($notifiable) { return ['database']; } } $user->notify((new OrderCommented)->dependsOn($order, $comment)); $comment->delete(); // the notification is deleted too
Documentation
Full documentation: Laravel Notification Dependencies Documentation.
Support & Security
See SUPPORT.md and SECURITY.md. Contributions are welcome; see CONTRIBUTING.md.
License
MIT. See LICENSE.
