Search by

pharaonic / laravel-notification-dependencies

Pharaonic

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

Documentation

pkg:composer/pharaonic/laravel-notification-dependencies

Fund package maintenance!

MoamenEltouny

Buy Me A Coffee

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

13.0.0 2026-11-07 05:04 UTC

README

PHP Version : 8.3 | 8.4 | 8.5 Laravel Version : 13.x License Build
Source Packagist Version Packagist Downloads

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.