ruvelo / laravel-inbox
The in-app notification inbox Laravel never shipped: a header bell, an inbox page and per-type preferences, on top of the database notification channel.
Requires
- php: ^8.3
- laravel/framework: ^12.4.1|^13.0
Requires (Dev)
- larastan/larastan: ^3.13
- laravel/pint: ^1.32
- orchestra/testbench: ^10.0|^11.0
- phpunit/phpunit: ^11.5|^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-05 10:17:06 UTC
README
Live demo Configuration Upgrading Developer guide Changelog
Laravel Inbox
A notification inbox for your Laravel app: a bell for your header, an inbox page and preferences, built on Laravel's own database notifications.
Quick start
composer require ruvelo/laravel-inbox
php artisan make:notifications-table # only if you don't have Laravel's notifications table yet
php artisan migrate
Put the bell in your layout:
<x-inbox::bell />
That's it. Every notification you send through the database channel now shows up in the bell and at /inbox. To give one a proper title and link, return title, body and url from its toArray(); see Using it. Want a look first? Click around the live demo.
What you get
- A bell with an unread count and the latest notifications, for any Blade layout.
- An inbox page at
/inbox: All and Unread tabs, grouped by day, filter by type, mark read or unread, delete. - A preferences page where people switch each notification type and channel on or off.
- Works with the notifications you already send: no new table for them, no changes to your classes.
- A JSON API for React, Vue and Inertia.
- Safe and cheap: only ever the signed-in person's own notifications, in a couple of queries.
- No frontend build step; light and dark mode; works without JavaScript.
Optional features
Both are off by default.
Live bell and inbox
The bell and inbox update the moment a notification arrives, over Laravel broadcasting (Reverb, Pusher or Ably). Without it, the bell checks every 30 seconds. Off by default: set INBOX_LIVE=auto in .env to turn it on whenever a broadcaster is configured (or true to always broadcast). Details.
Daily or weekly digests
People can ask for one daily or weekly email listing what they haven't read. Off by default: set INBOX_DIGESTS=true and make sure Laravel's scheduler runs. Details.
A quick tour
A bell for your header. One Blade tag. It shows the unread count, and opens on the latest notifications. Opening one marks it read in the background and takes you straight to it. The count keeps itself up to date while the tab is open, and updates instantly with live updates on.
An inbox page for everything else. All and Unread tabs, notifications grouped by day, a filter by type, and mark read, mark unread and delete on every item.
Preferences people can set themselves. Each notification type, each channel, one switch. Your notifications' via() respects them with one line.
Live, when you turn it on. With INBOX_LIVE=auto and a broadcaster, a new notification lights up the bell the moment it's stored, and the inbox page says "1 new notification" without reloading under the reader. Reads, deletes and "mark all as read" in one tab update the count in the others. No broadcaster? The bell keeps polling, as before.
Digest emails, if people want them. Off, daily or weekly, chosen on the preferences page. One clean, phone-friendly email listing what they haven't read since the last one, grouped by type, with a button to the inbox. Nothing unread, no email.
![]() |
![]() |
Light and dark, following each person's system setting (or your app's data-theme / .dark). |
Made for phones too, with the actions always in reach. |
Full feature list
- Zero changes to existing notifications. Anything you send through the
databasechannel appears. By convention,toArray()/toDatabase()returnstitle,body,url, and optionallyicon(an emoji or a short string) andactor(a name). Other shapes still show, titled after the class:InvoicePaidNotificationbecomes "Invoice paid". <x-inbox::bell />: unread badge (capped at 99+), a dropdown with the latest notifications, "Mark all as read", "View all" and "Preferences". Without JavaScript it's a link to the inbox. With it: an accessible dropdown (aria-expanded, Esc to close, focus moves in and back), read marks sent in the background, a polled unread count that pauses while the tab is hidden, and live updates over Laravel Echo whenwindow.Echoexists.- Live updates: every stored database notification, read, unread, delete and "mark all as read" is broadcast as
inbox.changedon the person's private channel, with the new unread count. Off by default;INBOX_LIVE=autoturns it on when a real broadcaster is configured. Works with Reverb, Pusher and Ably. Polling stays as the fallback. - Digest emails: an opt-in daily or weekly summary of unread notifications since the last digest, grouped by type and capped, as a Markdown mail.
inbox:send-digestsis scheduled for you; empty digests are never sent; every digest sent is recorded; per-type preferences are respected. - The inbox page at
/inbox: All and Unread tabs, grouped by Today, Yesterday and dates in your app's timezone, filter by type, mark read or unread, delete, mark all as read, pagination and helpful empty states. Clicking an item marks it read and follows its link, through a plain redirect that works without JavaScript. - Preferences at
/inbox/preferences: per notification type, people switch channels on and off. Types have labels, descriptions, groups, per-channel defaults, and can be required (shown, but always on). RespectsInboxPreferences: one trait, one line invia().- A JSON API for React, Vue and Inertia, over the session: only ever the signed-in user's own notifications.
- Safe by default: everything is escaped, links are only ever
http(s)or paths (javascript:URLs in stored data are dropped), and someone else's notification is a 404 on every route. - Cheap: the unread count is one indexed
COUNTquery, and the bell runs two queries however many notifications there are. - Fits in: the bell's styles are scoped and included once, so they can't touch your CSS. The pages can use your app's layout.
Using it
Put the bell in your layout, wherever your header is:
<header> … <x-inbox::bell /> </header>
It renders nothing for guests. Options: <x-inbox::bell :limit="8" :poll="60" label="Updates" class="ms-auto" />, and :user="$someone" to show another notifiable than the signed-in user.
Send notifications as you already do, with a title, body and url:
class InvoicePaid extends Notification { public function via(object $notifiable): array { return ['mail', 'database']; } public function toArray(object $notifiable): array { return [ 'title' => "Invoice {$this->invoice->number} paid", 'body' => "{$this->invoice->customer} paid {$this->invoice->total}.", 'url' => route('invoices.show', $this->invoice), 'icon' => '💸', ]; } }
That's all. subject, message and action_url work too, if that's what your notifications already use.
Live updates
Live updates are off by default. Turn them on in .env:
INBOX_LIVE=auto
auto broadcasts whenever a real broadcaster is configured (BROADCAST_CONNECTION is reverb, pusher or ably) and stays quiet with null or log; true always broadcasts.
The inbox broadcasts on the same private channel Laravel uses for broadcast notifications, App.Models.User.{id} (or whatever your model's receivesBroadcastNotificationsOn() returns), so there is nothing new to authorize if you already have it. If you don't have broadcasting yet:
php artisan install:broadcasting
That installs Reverb (or set up Pusher or Ably instead), creates resources/js/echo.js (which sets window.Echo) and routes/channels.php. Make sure routes/channels.php lets people listen on their own channel; Laravel's default does:
use Illuminate\Support\Facades\Broadcast; Broadcast::channel('App.Models.User.{id}', function ($user, $id) { return (int) $user->id === (int) $id; });
That's all. With INBOX_LIVE=auto and BROADCAST_CONNECTION set to reverb, pusher or ably, live updates are on: when a notification is stored through the database channel, or when someone reads, unreads or deletes one or marks everything read, an inbox.changed event goes out on their channel. The bell, already on the page, listens for it through window.Echo, updates its badge and refreshes its list; the inbox page shows a "1 new notification. Show them" banner. Without INBOX_LIVE (or with false, or auto and a null or log broadcaster), nothing is broadcast and the bell keeps polling every bell.poll seconds.
Broadcasts are queued like any ShouldBroadcast event, so run a queue worker (or use the sync queue). Put them on their own queue with inbox.live.queue.
Your own front end can listen too:
window.Echo.private(`App.Models.User.${userId}`).listen('.inbox.changed', (e) => { // e.reason: "created", "read", "unread", "deleted" or "read-all" // e.unread: the new unread count // e.notification: {id, type, type_label, title, body, url, icon, actor, created_at} for "created", else null });
Digest emails
Turn them on for your app:
INBOX_DIGESTS=true
The preferences page then gets an "Email digest" choice: Off (everyone starts there), Daily or Weekly. The package schedules inbox:send-digests every day at inbox.digests.schedule (08:00 in the inbox's timezone), so all you need is Laravel's scheduler running. To schedule it yourself instead, set schedule to null and add it to routes/console.php:
use Illuminate\Support\Facades\Schedule; Schedule::command('inbox:send-digests')->dailyAt('07:30')->withoutOverlapping();
Each run sends a digest to everyone whose period has passed since their last one (a day, or a week; with an hour's slack so a scheduler running a few seconds early doesn't skip a day). A digest lists their unread notifications created since the last digest (or over the last period, for the first one), grouped by type with a count per type, the newest first, at most digests.max_items of them, then "…and 4 more" and a button to the unread inbox. Each item links through the inbox, so opening it marks it read. If there's nothing unread, nothing is sent, and the next run looks again from the same point. Every digest sent is recorded in the inbox_digests table (Ruvelo\Inbox\Models\Digest), with the ids of the notifications it listed.
Preferences are respected per type: a type that offers a digest channel gets its own "Digest" switch on the preferences page and the digest follows it; otherwise the digest follows the type's "In app" (database) switch. Required and unregistered types are always included.
Inbox::preferences([ InvoicePaid::class => [ 'label' => 'Invoice paid', 'channels' => ['mail', 'database', 'digest'], 'defaults' => ['mail' => false], // no email each time; still in the digest ], ]);
php artisan inbox:send-digests # everything that's due
php artisan inbox:send-digests --frequency=weekly # only weekly ones
php artisan inbox:send-digests --dry-run -v # who would get one, sending nothing
The email is the inbox::mail.digest Markdown view, using Laravel's mail components and theme. Publish the views (--tag=inbox-views) to change its wording. It's sent with the Ruvelo\Inbox\Notifications\InboxDigest notification, through the mail channel only, so it never shows up in the inbox itself.
Describing a notification in code
Implement InboxNotification and the inbox stores your message with the notification; you don't need toArray():
use Ruvelo\Inbox\Contracts\InboxNotification; use Ruvelo\Inbox\InboxMessage; class TeammateJoined extends Notification implements InboxNotification { public function via(object $notifiable): array { return ['database']; } public function toInbox(object $notifiable): InboxMessage { return InboxMessage::make("{$this->user->name} joined your team") ->withUrl(route('team')) ->withActor($this->user->name); } }
Or decide how a type looks without touching it (handy for notifications from other packages, or ones already in the database):
Inbox::present(ExportReady::class, fn (array $data) => InboxMessage::make( 'Your export is ready', body: "{$data['rows']} rows", url: route('exports.show', $data['export_id']), icon: '📦', ));
Preferences
Register the types people can switch, in config/inbox.php or a service provider:
use Ruvelo\Inbox\Inbox; Inbox::preferences([ InvoicePaid::class => [ 'label' => 'Invoice paid', 'description' => 'When a customer pays one of your invoices.', 'group' => 'Billing', 'channels' => ['mail', 'database'], 'defaults' => ['mail' => false], // off until they turn it on ], SecurityAlert::class => [ 'label' => 'Security alerts', 'channels' => ['mail'], 'required' => true, // shown, can't be turned off ], ]);
Then let the notification respect them:
use Ruvelo\Inbox\Notifications\RespectsInboxPreferences; class InvoicePaid extends Notification { use RespectsInboxPreferences; public function via(object $notifiable): array { return $this->preferredChannels($notifiable, ['mail', 'database']); } }
Channels that aren't listed for a type, unregistered types, required types and on-demand notifiables (Notification::route(...)) always get through. To share one switch between several notifications, override inboxType() to return the same key. Choices live in their own table, one row per explicit choice; everything else follows the type's default.
Who sees what
Every route needs a signed-in user and only ever shows or changes that user's own notifications. Anyone else's notification is a 404, never a 403, so ids can't be probed. Guests are sent to your login route, or get a 403 in an app that doesn't have one yet (a fresh install before a starter kit), so you don't need auth in the middleware, though it's fine to add it.
Making it look like your app
The colours are CSS variables, scoped to the bell and the pages, using the Ruvelo house style. Override any of them in your own CSS:
.inbox-bell, .inbox-page { --inbox-accent: #0e7c66; --inbox-accent-soft: #e6f5f1; }
To put the inbox and preferences pages inside your app's chrome, point layout at your layout. The pages fill the section you name (and a title section), and bring their own scoped styles:
'layout' => 'layouts.app', 'section' => 'content',
For full control, publish the views. They land in resources/views/vendor/inbox:
php artisan vendor:publish --tag=inbox-views
For developers
PHP API
use Ruvelo\Inbox\Inbox; Inbox::unreadCount($user); // one indexed COUNT query Inbox::latest($user, 5); // newest first, read or not Inbox::query($user)->whereNull('read_at')->paginate(); Inbox::find($user, $id); // null if it isn't theirs Inbox::markRead($notification); // false if it already was Inbox::markUnread($notification); Inbox::markAllRead($user); // one query; returns how many Inbox::delete($notification); Inbox::message($notification); // how it looks: an InboxMessage Inbox::present(Type::class, fn (array $data, Notification $n) => InboxMessage::make('…')); Inbox::preferences([...]); // register switchable types Inbox::wants($user, InvoicePaid::class, 'mail'); Inbox::filterChannels($user, InvoicePaid::class, ['mail', 'database']); Inbox::preferencesFor($user); // [type => [channel => bool]], defaults filled in Inbox::updatePreferences($user, [InvoicePaid::class => ['mail' => true]]); Inbox::live(); // are inbox changes being broadcast? Inbox::broadcastChannel($user); // "App.Models.User.1" Inbox::digestsEnabled(); Inbox::digestFrequency($user); // "none", "daily" or "weekly" Inbox::setDigestFrequency($user, 'weekly'); // false if unchanged Inbox::digest($user, 'daily', now()->subDay()); // a DigestSummary: total, groups, more(), subject()
The write methods accept Laravel's own DatabaseNotification (what $user->notifications returns) as well as the package's Ruvelo\Inbox\Models\Notification, which reads the same table and adds message(), isUnread() and the ownedBy($user) scope.
InboxMessage is a small immutable value object: make($title, $body, $url, $icon, $actor), with…() methods that return copies, initials(), excerpt() and toArray().
JSON API
For React, Vue and Inertia front ends. It runs on the session (web middleware), so send the CSRF token on writes as you would for any form, and only ever touches the signed-in user's own notifications. Paths are relative to /api/inbox.
| Request | Does |
|---|---|
GET /notifications |
List, newest first. ?filter=unread, ?type=<class>, ?per_page= up to 100. meta.unread and meta.types included |
GET /notifications/count |
{"unread": 3}: cheap enough to poll |
GET /notifications/{id} |
One notification |
POST /notifications/{id}/read |
Mark read; returns the notification |
POST /notifications/{id}/unread |
Mark unread; returns the notification |
POST /notifications/read-all |
{"marked": 3, "unread": 0} |
DELETE /notifications/{id} |
Delete. 204 |
GET /preferences |
Every registered type with its label, description, group, required and channels: {mail: true, …}. With digests on, also digest: {frequency: "none", frequencies: ["none", "daily", "weekly"]} |
PUT /preferences |
{"preferences": {"App\\Notifications\\InvoicePaid": {"mail": false}}}; only the pairs sent change. With digests on, {"digest": "weekly"} too (either or both). 422 for unknown types, channels or frequencies, or for turning off a required type |
A notification looks like this:
{
"id": "9d1c…", "type": "App\\Notifications\\InvoicePaid", "type_label": "Invoice paid",
"title": "Invoice INV-2288 paid", "body": "Bluefin Studio paid €4,800.00.", "url": "/invoices/INV-2288",
"open_url": "https://app.test/inbox/9d1c…/open", "icon": "💸", "actor": null, "initials": "I",
"read": false, "read_at": null, "created_at": "2026-10-08T09:12:00+00:00",
"time_ago": "48 minutes ago", "day": "Today", "payload": { "…": "the stored data" }
}
Someone else's notification is a 404; a guest gets a 401.
Web routes
GET /inbox |
The inbox (?filter=unread, ?type=) |
GET /inbox/preferences, PUT /inbox/preferences |
Preferences |
GET /inbox/{id}/open |
Mark read and follow the link |
POST /inbox/{id}/read, /unread, DELETE /inbox/{id} |
One notification; answers JSON when asked for it |
POST /inbox/read-all |
Mark everything read |
GET /inbox/count, GET /inbox/bell |
What the bell polls, and its list as HTML |
Events
| Event | When |
|---|---|
NotificationRead |
A notification was marked read, one at a time or by opening it |
NotificationUnread |
A read notification was marked unread |
AllNotificationsRead |
Someone marked everything read; has notifiable and count |
NotificationDeleted |
A notification was deleted |
PreferencesUpdated |
Someone changed their per-type preferences; has notifiable and the changes |
InboxChanged |
Broadcast (inbox.changed) when live updates are on; has reason, unread, notification and channel |
DigestSent |
A digest email went out; has notifiable and the recorded digest |
All in Ruvelo\Inbox\Events, and only fired when something actually changed.
Exceptions
UnknownPreference (a type or channel that isn't registered, or a digest frequency that isn't offered), RequiredPreference (turning off a required type) and InvalidPreferenceType (a malformed registration), all extending Ruvelo\Inbox\Exceptions\InboxException.
In your tests
use Ruvelo\Inbox\Models\Notification; Notification::factory()->to($user)->count(3)->create(); Notification::factory()->to($user)->read()->ofType(InvoicePaid::class) ->message(InboxMessage::make('Invoice paid', url: '/invoices/1'))->create();
To test your own code against live updates and digests:
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Notification as NotificationFake; use Ruvelo\Inbox\Events\InboxChanged; use Ruvelo\Inbox\Notifications\InboxDigest; config(['inbox.live.enabled' => true]); Event::fake([InboxChanged::class]); $user->notify(new InvoicePaid($invoice)); Event::assertDispatched(InboxChanged::class, fn ($e) => $e->reason === 'created'); NotificationFake::fake(); config(['inbox.digests.enabled' => true]); Inbox::setDigestFrequency($user, 'daily'); $this->artisan('inbox:send-digests')->assertSuccessful(); NotificationFake::assertSentTo($user, InboxDigest::class);
Integrations
Laravel Reverb, Pusher, Ably and Echo. Live updates use Laravel broadcasting and nothing else: whichever driver BROADCAST_CONNECTION names, on the private channel your app already authorizes for broadcast notifications. On the page, the bell and inbox use window.Echo if it's there when the page loads (Echo set up by install:broadcasting, or your own), and fall back to polling if it isn't. Notifications that also use Laravel's broadcast channel still refresh the bell, as before.
Inertia, React and Vue. Front ends that don't render the Blade bell use the JSON API, and listen for .inbox.changed on the user's channel themselves (see Live updates): e.unread is the new badge count, and e.notification is ready to prepend to a list.
ruvelo/laravel-comments. Its mention notifications are stored through the database channel with the title, body, url and actor keys the inbox reads, so mentions show up in the bell and inbox, arrive live (when live updates are on), and are included in digests without any setup. To let people switch them off, register the mention notification's class (or its inboxType()) with Inbox::preferences() like any other type.
Using an AI coding agent?
The package ships Laravel Boost guidelines in resources/boost/guidelines/core.blade.php. With Boost installed (composer require laravel/boost --dev), run php artisan boost:install and pick ruvelo/laravel-inbox from the third-party packages (or php artisan boost:update --discover if Boost is already set up). Your agent then knows how to put the bell in your layout, make notifications show nicely, respect preferences, and use the JSON API, and what not to do.
Requirements
| Laravel | PHP | Tested in CI |
|---|---|---|
| 12 (12.4.1+) | 8.3, 8.4, 8.5 | yes |
| 13 | 8.3, 8.4, 8.5 | yes |
- The
notificationstable:php artisan make:notifications-tableif you don't have it yet - A notifiable model that uses Laravel's
Notifiabletrait (usuallyUser) - Optional, for live updates: Laravel broadcasting (
php artisan install:broadcasting) and Laravel Echo on the page - Optional, for digest emails: a working mailer and Laravel's scheduler (
* * * * * php artisan schedule:run)
Configuration reference
Publish the config file if you want to change the defaults:
php artisan vendor:publish --tag=inbox-config
| Key | Default | |
|---|---|---|
path |
inbox (INBOX_PATH) |
URL prefix for the inbox and preferences pages |
domain |
null |
Serve them on their own (sub)domain |
middleware |
['web'] |
Applied to every page; signing in is always required |
routes |
true |
Set to false to register routes yourself (copy routes/web.php) |
api.enabled |
true (INBOX_API) |
The JSON API |
api.prefix |
api/inbox |
Where the JSON API lives |
api.middleware |
['web'] |
Session authentication: keep web, or use your own guard |
layout |
null |
Your layout view for the pages; null uses the package's own |
section |
content |
The section of your layout the pages fill |
bell.limit |
6 |
How many notifications the dropdown shows |
bell.poll |
30 |
Seconds between unread-count checks; 0 turns polling off |
bell.echo |
true |
Listen on the user's private channel when Laravel Echo is on the page (the bell and the inbox page) |
live.enabled |
false (INBOX_LIVE) |
Broadcast inbox.changed: auto when broadcasting.default isn't null or log, true always, false never |
live.queue |
null |
The queue broadcasts go on; null uses the default |
digests.enabled |
false (INBOX_DIGESTS) |
Offer digest emails on the preferences page, and send them |
digests.frequencies |
['daily', 'weekly'] |
The choices besides Off |
digests.schedule |
08:00 |
When the package schedules inbox:send-digests each day, in timezone; null to schedule it yourself |
digests.max_items |
10 |
Notifications listed in one email; the rest are counted |
per_page |
25 |
Notifications per page on the inbox |
timezone |
your app's | Timezone for "Today", "Yesterday" and dates |
preferences |
[] |
Notification types people can switch on and off |
channels |
database → In app, mail → Email, digest → Digest… |
How channels are labelled on the preferences page |
notifications_table |
notifications |
Laravel's notifications table |
table_prefix |
inbox_ |
The package's tables: {prefix}preferences, {prefix}digest_subscriptions and {prefix}digests |
run_migrations |
true |
Set to false if you publish the migrations and run them yourself (--tag=inbox-migrations) |
Upgrading
From 1.2.0 to 1.2.1
Live updates are now off by default. If your app broadcasts (BROADCAST_CONNECTION is reverb, pusher or ably) and you want to keep them, set INBOX_LIVE=auto in .env. If you published the config in 1.2.0, its live.enabled line still reads env('INBOX_LIVE', 'auto'), so nothing changes for you until you edit it.
From 1.1 to 1.2
From 1.1, this is a backwards-compatible release:
composer update ruvelo/laravel-inbox, thenphp artisan migrate. Two new tables (inbox_digest_subscriptions,inbox_digests); nothing existing changes. If you published the migrations (run_migrationsfalse), publish again (--tag=inbox-migrations) and migrate.- Live updates (from 1.2.1, off until you set
INBOX_LIVE=autoortrue) queue inbox changes as broadcasts on each user's private channel. That channel is the one Laravel's broadcast notifications use, so it's normally authorized already. - Digest emails stay off until you set
INBOX_DIGESTS=true. - If you published the views, re-publish them (or copy the changes) to get the live banner, the bell's
inbox.changedlistener and the digest choice on the preferences page. Published views from 1.x keep working as they are. - If you published the config, the new
liveanddigestskeys fall back to their defaults; add them to change them.
The stored notification format, the JSON shapes and every existing route are unchanged.
Contributing
Pull requests are welcome. Clone, composer install, then composer check runs code style (Pint), static analysis (PHPStan level 8) and the tests, exactly as CI does. See CONTRIBUTING.md and the changelog.
The demo and screenshots are built from the package itself: composer demo writes the static demo into build/, and demo/screenshots.sh regenerates art/.
Credits
Built by François Bultez at Valtry, the website security scanner, and everyone who contributes.
License
MIT. See LICENSE.





