ranger / notification
Realtime user-to-user notifications for Laravel: Eloquent-backed, broadcast over private channels, with a drop-in bell dropdown view.
Requires
- php: ^8.2
- illuminate/broadcasting: ^11.0|^12.0
- illuminate/database: ^11.0|^12.0
- illuminate/events: ^11.0|^12.0
- illuminate/http: ^11.0|^12.0
- illuminate/pagination: ^11.0|^12.0
- illuminate/routing: ^11.0|^12.0
- illuminate/support: ^11.0|^12.0
- illuminate/view: ^11.0|^12.0
Requires (Dev)
- orchestra/testbench: ^9.0|^10.0
README
Realtime user-to-user notifications for Laravel. Eloquent-backed, broadcast over private channels via Laravel's own broadcasting system (Reverb, Pusher, Ably — whatever your app uses), with a drop-in bell dropdown view.
Requirements
- PHP 8.2+
- Laravel 11 or 12
- (Optional, for realtime) a configured broadcast driver and Laravel Echo
Note for Laravel 11 apps: Laravel 11 is past its security-fix window and has open security advisories, so Composer 2.10+ refuses to install it by default. If your app is still on Laravel 11 you have already dealt with this, but for a fresh install you may need:
composer config policy.advisories.block false
Installation
composer require ranger/notification php artisan migrate
The service provider is auto-discovered. The migration creates a
ranger_notifications table.
Optionally publish the config, views, or migration:
php artisan vendor:publish --tag=notification-config php artisan vendor:publish --tag=notification-views php artisan vendor:publish --tag=notification-migrations
Sending notifications
From anywhere in your app (controller, job, listener):
use Ranger\Notification\Notifier; app(Notifier::class)->send( fromUserId: auth()->id(), // or null for system notifications toUserIds: [3, 7, 12], // one id or an array message: 'A new order was placed.' );
Each recipient gets their own row and, when broadcasting is enabled, a
notification.created event on their private channel
notifications.{userId}. Channel authorization is registered by the
package: users can only subscribe to their own channel.
HTTP endpoints
Registered automatically under the configurable prefix (default
/notifications) behind ['web', 'auth'] middleware:
| Method | URI | Name | Returns |
|---|---|---|---|
| GET | /notifications | notifications.index | { unread_count, notifications: <paginator> } |
| POST | /notifications/{id}/read | notifications.read | { status: "ok" } (404 if not yours) |
| POST | /notifications/read-all | notifications.read-all | { status: "ok" } |
There is intentionally no HTTP endpoint for creating notifications —
send them from server-side code with Notifier::send().
Bell dropdown view
Add to any Blade layout used by authenticated pages:
@include('notification::bell')
Requirements in your layout:
<meta name="csrf-token" content="{{ csrf_token() }}">in<head>- (Optional) Laravel Echo configured on
window.Echofor realtime badge updates; without it the bell still works and refreshes when opened.
Configuration
config/notification.php:
return [ 'route' => [ 'prefix' => 'notifications', 'middleware' => ['web', 'auth'], ], 'broadcast' => [ 'enabled' => true, 'channel_prefix' => 'notifications', ], ];
Testing
composer test
License
MIT — see LICENSE.md.