laravel-notification-dependencies maintained by pharaonic
Description
Attach Laravel database notifications to Eloquent models and delete them automatically when any of those models is deleted.
Author
Last update
2026/11/07 06:04
(dev-develop)
License
Downloads
0
Tags
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.