ranger/notification

Realtime user-to-user notifications for Laravel: Eloquent-backed, broadcast over private channels, with a drop-in bell dropdown view.

Maintainers

Package info

github.com/i-sazzad/notification

pkg:composer/ranger/notification

Transparency log

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 3

Open Issues: 0

v1.0.0 2026-07-20 06:16 UTC

This package is auto-updated.

Last update: 2026-07-20 08:37:06 UTC


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.Echo for 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.