Notification Dependencies: No more notifications about deleted things
Notification Dependencies ties each Laravel database notification to the Eloquent models it is about. Delete the order, the comment, or the friend request, and every notification that depends on it is deleted with it, for every recipient, without a cleanup job.
Everything you need to keep notifications relevant
Two traits and one call when you send, and stale notifications clean themselves up.
Attach to Models
Chain dependsOn($order, $comment) when you send, or declare dependencies() in the notification class.
Automatic Cleanup
Deleting any dependency deletes every stored notification that depends on it, in set-based batches.
Many Dependencies
One notification can depend on several models of different types, with integer, UUID, or ULID keys.
Queue Safe
Only identities travel through the queue, and a dependency deleted while the job waits still wins.
Soft Delete Aware
Remove notifications on soft delete, or keep them until forceDelete() with one setting.
Queryable Relation
Load, count, and filter dependentNotifications like any Eloquent relation.
A quick look
Send a notification that depends on an order and a comment, then delete the comment.
1use App\Notifications\OrderCommented;2 3$order->customer->notify(4 (new OrderCommented)->dependsOn($order, $comment)5);6 7$comment->delete(); // the customer's notification is deleted too8 9$order->dependentNotifications()->count(); // notifications still about this orderNotification Dependencies Questions
Quick answers about installing and using Notification Dependencies.
What is Notification Dependencies?
Attach Laravel database notifications to Eloquent models and delete them automatically as soon as any of those models is deleted. It's a free, open-source Laravel package by Pharaonic.
How do I install Notification Dependencies?
Run composer require pharaonic/laravel-notification-dependencies in your project's root directory, then php artisan migrate. Your application needs Laravel's notifications table first (php artisan notifications:table).
What does Notification Dependencies require?
The latest release requires PHP 8.3+ and Laravel 13.
Does it delete mail or broadcast notifications?
No. Only rows stored by the database channel are linked and deleted. Every other channel of the same notification is sent exactly as before.
Does it work with queued notifications?
Yes. dependsOn() keeps only each model's type and key, so a queued notification carries no extra models, and a dependency deleted while the job waits still deletes the notification once it is stored.
What happens on a soft delete?
By default, soft deleting a dependency deletes its notifications. Set delete_on_soft_delete to false to keep them until the model is force deleted.
Do I have to add a trait to every model?
By default, yes: dependencies use HasDependentNotifications. Turn on all_models to accept any model, at the cost of one indexed lookup on every model deletion.
Is Notification Dependencies free to use?
Yes. Notification Dependencies is open source under the MIT license, so you can use it in personal and commercial projects.
Where can I find the Notification Dependencies documentation?
Read the Notification Dependencies documentation for setup, configuration, and usage examples.
How do I report a bug or contribute to Notification Dependencies?
Open an issue or a pull request on GitHub, ask in GitHub Discussions, or chat with us on Discord.
Ready to dig in?
Read the full documentation for installation, configuration, declaring dependencies, dependable models, soft deletes, queued notifications, the NotificationDependency model, real-world examples, and troubleshooting.