Feedback

Notification

A bell button with the unread count that opens a panel of the user's notifications, read from Laravel's database notifications, split into Unread and Read tabs and grouped by day. Inside a Livewire component, each notification can be marked as read or removed, and the panel can refresh itself by polling or by Laravel Echo.

Blade

A bell button; with unread notifications, a blue dot on it shows the count (up to 99), and its accessible name says "Notifications (3 unread)". Clicking it opens a panel titled "Notifications" with Unread and Read tabs. Each notification shows an icon colored by its type, the title, the message, the time ("5 minutes ago") and a link when it has a url. With grouped, they are under "Today", "Yesterday", "This week" and "Earlier".

The notifications are the authenticated user's notifications(), newest first, up to 50. Each one's data gives title, message, type (success, error, warning, info), icon and url:

Actions and live updates #

Rendered inside a Livewire component, each unread notification gets a "Mark as read" button, each read one a "Remove" button, and the Unread tab a "Mark all as read" button; they update the database and the item collapses. With echo, a new notification broadcast to the user refreshes the panel at once (Laravel Echo must be on the page); interval="30" refreshes it every 30 seconds instead.

Blade

Inline, from your own data #

The panel is placed in the page, without the bell, and lists $activity: arrays or objects with the same keys (id, title, message, type, url, created_at, read_at). compact drops the icons and tightens the spacing; without tabs it also drops the "Notifications" title.

Order shipped

Order #1042 is on the way.

5 minutes ago

Payment failed

The card of Grace Hopper was declined.

3 hours ago

Password changed

Your password was changed from a new device.

1 day ago

Blade

Bell with your own data #

items works with the bell too: here it lists the same activity, grouped by day.

Blade

Sizes #

size scales the bell and the panel, from xs to 3xl.

Blade

Empty #

With no unread notifications the bell has no dot and the Unread tab shows its empty message, changed here with list-unread:empty.

Notifications

All caught up!

No read notifications yet

Blade

Customization #

Prefixed attributes reach the parts: trigger: the bell, popover: the panel, tab-unread: and tab-read: the tabs, list-unread:item: each notification.

Blade

Reference

tk:notification
└── tk:notification.panel
    └── tk:notification.list
        └── tk:notification.item ...

tk:notification

Prop Type Default Description
items array | Collection the user's The notifications to show. Without it, the authenticated user's database notifications.
limit int 50 How many of the user's notifications are loaded.
guard string default guard The auth guard of the user.
variant string dropdown inline renders the panel in place, without the bell.
tabs bool true Splits the panel in Unread and Read tabs. false shows only the unread ones.
grouped bool false Groups the notifications by day.
compact bool false A narrower panel, without icons, with less spacing.
markAll bool true Shows "Mark all as read" in the Unread tab, inside Livewire.
interval int null Refreshes the panel every that many seconds, inside Livewire.
echo bool false Refreshes the panel when a notification is broadcast to the user, inside Livewire, with Laravel Echo.
size string md xs, sm, md, lg, xl, 2xl or 3xl.

The inner tags (tk:notification.panel, .list, .item) are rendered by this one; their parts are reached through the prefixes below.

Prefixes

Prefix Goes to
trigger: The bell button (trigger:variant="ghost").
dropdown:, popover: The dropdown and its panel (popover:class="max-w-md").
section: The panel section, with its title.
tab-unread:, tab-read: The two tabs (tab-unread:label="New").
list-unread:, list-read: The two lists (list-unread:empty="All caught up").
tab-group:, tabs:, tab-panels: The tab group, the row of tabs and the panels around the lists.
tab-panel-unread:, tab-panel-read: The two tab panels.
mark-all: The "Mark all as read" button.

Customization

Classes and attributes on the tag go to its wrapper. To reach the parts, prefix the attribute (listed in the Reference above).

Inside list-unread: and list-read:, the list takes item: (each notification), group-label: (the day headings) and empty: (the empty message). Inside item:, the parts are icon:, icon-container:, content:, message:, description:, time:, actions:, bullet:, read: and remove:: list-unread:item:time:class="text-xs".

blade

Accessibility

The bell's accessible name includes the unread count, and when the count goes up (a poll or Echo) it is announced politely, and the panel is a role="dialog" named "Notifications", with tabs that follow the WAI-ARIA tabs pattern. Each notification with a url is a link reached with Tab; the action buttons have names ("Mark as read", "Remove notification") through their tooltips.

Behavior notes

  • The actions only touch the authenticated user's own notifications: marking as read only unread ones, removing only read ones. A guard sent from the browser is used only when it is one of the app's guards.

  • A Livewire component with a $notificationGuard property uses that guard for the actions, whatever guard the browser sends. Make it protected (or #[Locked]) so the browser cannot change it:

    php

    It only affects the actions: pass the same guard to the tag so the panel lists that user's notifications.

  • With items, the actions still call the same methods, which act on the user's database notifications with those ids, and "Mark all as read" marks only the listed ones; outside that case they only hide the item.

  • Without a logged-in user and without items, the panel shows its empty messages ("No new notifications").

  • A url with an unsafe scheme (javascript:...) is ignored.

  • Inside a Livewire component, a tallkit:dismiss event dispatched on an item hides it, as "Mark all as read" does with the items of its tab.

  • A component method named notificationMarkAsRead, notificationMarkAllAsRead or notificationDelete is called instead of the built-in action, with the same arguments ($id or $ids, then $guard), unvalidated: they come from the browser, so the method checks them itself (an id is a string or int, $ids a list of limited size, $guard one of the app's guards). TALLKit\Livewire\NotificationActions::user($this, $guard) returns the user the built-in actions would use (honoring $notificationGuard and checking the guard), or null.