Real-Time Notifications with Laravel 11 and Pusher
How to add real-time notifications to a Laravel 11 application with Pusher: event broadcasting, private channels and front-end listening.
Real-time notifications (a new message, an order, an alert) transform an application's experience. Here's the approach I use in production with Laravel 11 and Pusher. I published a detailed version of this guide on Medium; this article summarizes the architecture.
1. Configure broadcasting
Laravel broadcasts events to a WebSocket service. Pusher is the simplest to set up. You define the broadcast driver and keys in the environment file.
// .env
BROADCAST_CONNECTION=pusher
PUSHER_APP_ID=your-app-id
PUSHER_APP_KEY=your-app-key
PUSHER_APP_SECRET=your-app-secret
PUSHER_APP_CLUSTER=eu2. Create a broadcastable event
The event implements ShouldBroadcast and exposes the channel it will be emitted on. A private channel guarantees only the relevant user receives the notification.
class OrderShipped implements ShouldBroadcast
{
public function __construct(public Order $order) {}
public function broadcastOn(): PrivateChannel
{
return new PrivateChannel('orders.' . $this->order->user_id);
}
}3. Listen on the front-end
With Laravel Echo, you subscribe to the private channel and react to the event in real time, with no page reload.
window.Echo.private(`orders.${userId}`)
.listen('OrderShipped', (e) => {
showToast(`Order #${e.order.id} shipped!`);
});This same architecture powers notifications, live dashboards and instant messaging. For the full version, including private-channel authentication, read the detailed guide:
Read the full guide on Medium ↗Got a premium web project in mind?
Describe your goal. First consultation free, no commitment.
Let's talk about your project