roundly-consulting / notifications-for-laravel
Typed notifications for Laravel: an in-app inbox with collapsing and contexts, per-user channel preferences, mandatory types, email de-dup, quiet hours, digests and date-relative reminders.
Package info
github.com/roundly-consulting/notifications-for-laravel
pkg:composer/roundly-consulting/notifications-for-laravel
Fund package maintenance!
Requires
- php: ^8.4
- illuminate/auth: ^13.0
- illuminate/bus: ^13.0
- illuminate/cache: ^13.0
- illuminate/console: ^13.0
- illuminate/container: ^13.0
- illuminate/contracts: ^13.0
- illuminate/database: ^13.0
- illuminate/encryption: ^13.0
- illuminate/events: ^13.0
- illuminate/http: ^13.0
- illuminate/mail: ^13.0
- illuminate/notifications: ^13.0
- illuminate/pagination: ^13.0
- illuminate/queue: ^13.0
- illuminate/routing: ^13.0
- illuminate/support: ^13.0
- illuminate/translation: ^13.0
- illuminate/validation: ^13.0
- illuminate/view: ^13.0
- roundly-consulting/crypto-for-laravel: ^2.0
- roundly-consulting/enums-for-laravel: ^2.0
- roundly-consulting/options-for-laravel: ^2.0
- roundly-consulting/package-toolkit-for-laravel: ^2.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.18
- nunomaduro/collision: ^8.5
- orchestra/testbench: ^11.0
- pestphp/pest: ^5.0
- pestphp/pest-plugin-arch: ^5.0
- pestphp/pest-plugin-laravel: ^5.0
- phpstan/extension-installer: ^1.4
- roundly-consulting/contacts-for-laravel: ^2.0
- roundly-consulting/testing-for-laravel: ^2.0
Suggests
- roundly-consulting/contacts-for-laravel: Route mail to the user's primary (or verified) email contact.
- roundly-consulting/teams-for-laravel: Resolve recipients by team role or membership (docs recipe).
Provides
None
Conflicts
None
Replaces
None
README
Notifications for Laravel
One place to register your app's notification types and deliver them consistently: an in-app inbox with collapsing and contexts, email with de-duplication, per-user channel preferences, mandatory types, quiet hours, digests and reminders relative to a date. Features call one API; delivery, preferences and suppression rules live in the package.
Installation
Requires PHP 8.4 or newer, Laravel 13, and the hash, mbstring and openssl extensions (required through crypto-for-laravel).
composer require roundly-consulting/notifications-for-laravel php artisan vendor:publish --tag="notifications-migrations" php artisan vendor:publish --tag="options-migrations" php artisan migrate
Held mail, digests and reminders go out from the sweep — schedule it every minute:
Schedule::command('notifications:sweep')->everyMinute()->withoutOverlapping(10)->onOneServer();
Usage
Describe a type once (it needs a view policy on its subject, Company implementing
ProvidesNotificationRecipients, and a User with Notifiable + ReceivesNotifications):
use Illuminate\Database\Eloquent\Model; use RoundlyConsulting\Notifications\NotificationPayload; use RoundlyConsulting\Notifications\NotificationType; // app/Notifications/Types/RequestAwaitingApproval.php — listed in config('notifications.types') final class RequestAwaitingApproval extends NotificationType { public function key(): string { return 'request.awaiting_approval'; } public function category(): string { return 'requests'; } public function subject(): ?string { return PurchaseRequest::class; } // access check: Gate "view" on it public function window(): ?string { return 'PT5M'; } // 10 events in 5 min → 1 item, 1 mail public function title(NotificationPayload $p): string { return __('app.notifications.awaiting', ['ref' => $p->data['reference'], 'count' => $p->count]); } public function url(NotificationPayload $p): ?string { return route('requests.show', $p->subjectKey); } public function context(?Model $subject): ?Model { return $subject?->company; } // "Acme s.r.o." label }
Then send it from a feature — inbox, mail, preferences, de-dup, quiet hours and access are applied for you — and read the user's inbox:
use RoundlyConsulting\Notifications\Facades\Notifications; use RoundlyConsulting\Notifications\Recipients; Notifications::send( 'request.awaiting_approval', $request, Recipients::role($request->company, 'approver'), ['reference' => $request->reference], actor: $request->author, ); $items = Notifications::inbox($user)->unread()->paginate(); // InboxItemResource::collection($items) Notifications::inbox($user)->unreadCount(); // 3 Notifications::inbox($user)->markAllRead();
Documentation
The full documentation — configuration, every feature and its API, and testing — lives on our website: roundly-consulting.com/open-source/docs/notifications-for-laravel
Release notes are in CHANGELOG.md. To contribute, see the contributing guide.
Support our work
This package is free and open source, built and maintained by Roundly Consulting. If it saves you time, please consider supporting our open-source work — a one-time donation, a monthly pledge on Patreon or a crypto donation helps fund maintenance, new features and new packages.
License
The MIT License (MIT). See LICENSE.md.