Broadcasting in Laravel/Node — Realtime

Laravel broadcasting turns an event on the server (a PHP class such as OrderStatusChanged) into a message on a WebSocket channel (the name of a line). An…

Eko marks #12 as Ready for pickup on the tablet, and Mr. Darto's phone gets the news right away. Between the two sits Laravel broadcasting. Broadcasting turns an event on the server (a PHP class that stands for one thing that happened, such as OrderStatusChanged) into a message on a WebSocket channel (the name of a line). Every frontend (the code in the browser) listening to that channel receives it right away.

Think of Laravel as the laundry's office, where the news is made. The WebSocket server is a loudspeaker wired to the customers' phones, and each channel is one line on that loudspeaker. There are three kinds of line:

The loudspeaker can be Laravel's own (Reverb), or a Node server of yours that gets the news from Laravel through Redis (the loudspeaker of the Pub/Sub with Redis lesson).

The broadcast event

This is the event class:

<?php

namespace App\Events;

use App\Models\Order;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class OrderStatusChanged implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public function __construct(public Order $order) {}

    public function broadcastOn(): array
    {
        return [new PrivateChannel('orders.'.$this->order->id)];
    }

    public function broadcastWith(): array
    {
        return ['id' => $this->order->id, 'status' => $this->order->status];
    }
}

Eko's tablet calls a controller (Laravel code that answers a request). The controller saves the new status, then sends the event with dispatch:

// the controller Eko's tablet calls
$order->update(['status' => 'Ready for pickup']);
OrderStatusChanged::dispatch($order);

Guess before you read on. On the laptop, QUEUE_CONNECTION=database (Laravel 13's default), and no php artisan queue:work is running. When does Mr. Darto's phone get the news?

Who may listen: routes/channels.php

In routes/channels.php, each private and presence channel has a callback that decides who may subscribe:

use App\Models\Order;
use App\Models\User;
use Illuminate\Support\Facades\Broadcast;

Broadcast::channel('orders.{order}', function (User $user, Order $order) {
    return $user->id === $order->user_id;
});

Broadcast::channel('board', function (User $user) {
    return $user->is_staff ? ['id' => $user->id, 'name' => $user->name] : null;
});

Reverb: Laravel's WebSocket server

php artisan install:broadcasting --reverb installs laravel/reverb (1.12.0, checked 11 October 2026), laravel-echo (2.6.1) and pusher-js (8.6.0), then fills in .env (the app's settings file). Reverb speaks the Pusher protocol, the message rules of Pusher, a paid WebSocket service. So Echo talks to Reverb through pusher-js. Other drivers (the way Laravel delivers messages) with the same protocol: Pusher itself, Ably, or a server such as Soketi.

Run these two programs at the same time, in two terminals:

php artisan reverb:start          # listens on 0.0.0.0:8080
php artisan queue:work            # runs the BroadcastEvent jobs

Echo on the frontend

On the frontend, you create Echo once, then use it to listen to channels:

import Echo from 'laravel-echo'
import Pusher from 'pusher-js'
window.Pusher = Pusher

window.Echo = new Echo({
  broadcaster: 'reverb',
  key: import.meta.env.VITE_REVERB_APP_KEY,
  wsHost: import.meta.env.VITE_REVERB_HOST,
  wsPort: import.meta.env.VITE_REVERB_PORT ?? 80,
  wssPort: import.meta.env.VITE_REVERB_PORT ?? 443,
  forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? 'https') === 'https',
  enabledTransports: ['ws', 'wss'],
})

Echo.private('orders.12').listen('OrderStatusChanged', (e) => {
  console.log(e.status) // Ready for pickup
})

Or: your own Node server, fed by Redis

If your realtime server is Node (Socket.IO on localhost:3000), Laravel can publish events to Redis with BROADCAST_CONNECTION=redis. Tried with Laravel 13.35.0's RedisBroadcaster and APP_NAME=Laundry. The message that appears in Redis:

channel: laundry-database-private-orders.12
message: {"event":"App\\Events\\OrderStatusChanged","data":{"id":12,"status":"Ready for pickup","socket":null},"socket":null}

The Redis channel name starts with Laravel's Redis prefix. By default it is Str::slug(APP_NAME) plus -database-. The Node server listens to a pattern for those channels, then passes each message on to a Socket.IO room:

const sub = createClient({ url: 'redis://localhost:6379' })
await sub.connect()
await sub.pSubscribe('laundry-database-private-orders.*', (message, channel) => {
  const { data } = JSON.parse(message)
  const id = channel.split('.').pop()                    // "12"
  io.to(`order:${id}`).emit('order:status', { id: data.id, status: data.status })
})

This code uses the redis package (write import { createClient } from 'redis' at the top of the file) and io from your Socket.IO server.

On this road routes/channels.php is not used. The Node server decides who may join the room order:12, with the ticket and join checks from the previous lesson. The frontend uses socket.io-client too, not Echo with Reverb.

From tablet to phone: OrderStatusChanged end to end

Each step of the news through Reverb, in order:

# Where What happens
1 Mr. Darto's phone (since the page opened) Echo.private('orders.12'), POST /broadcasting/auth answered 200
2 Eko's tablet marks #12 as Ready for pickup, a request to Laravel
3 Laravel $order->update(...), OrderStatusChanged::dispatch($order), the job goes into the queue
4 queue:work runs the job: name App\Events\OrderStatusChanged, channel private-orders.12, data {"id":12,"status":"Ready for pickup"}
5 Reverb receives the event from Laravel over HTTP, sends it to every connection on private-orders.12
6 Mr. Darto's phone the OrderStatusChanged listener runs, e.status = Ready for pickup

⚠️ No worker, a missing dot, a forgotten prefix

TL;DR: Laravel broadcasting turns an event on the server (a PHP class such as OrderStatusChanged) into a message on a WebSocket channel (the name of a line). An event implementing ShouldBroadcast goes out through the queue (a list of jobs that run later), so it needs the worker php artisan queue:work. ShouldBroadcastNow goes right away. The channel comes from broadcastOn() (PrivateChannel('orders.12') becomes private-orders.12), the content from broadcastWith(), and the event's name is App\Events\OrderStatusChanged. routes/channels.php decides who may subscribe to private and presence channels (private plus a list of who is there; the callback returns an array of user data) through POST /broadcasting/auth. Reverb (1.12.0) is Laravel's WebSocket server, which speaks the Pusher protocol. Echo (2.6.1), its JavaScript library, listens with Echo.private('orders.12').listen('OrderStatusChanged', ...). With BROADCAST_CONNECTION=redis, Laravel publishes to Redis (on a channel prefixed laundry-database-), and your Node server passes it on to a Socket.IO room. On that road, authorisation happens in Node.

⚡ An event becomes a message on a channel

Write:

// the controller Eko's tablet calls
$order->update(['status' => 'Ready for pickup']);
OrderStatusChanged::dispatch($order);

Meaning: Laravel broadcasting turns an event (a PHP class that stands for something that happened, here OrderStatusChanged) sent with dispatch into a message on a WebSocket channel (the name of a line). Every frontend (the code in the browser) listening to that channel receives it right away. A driver (a WebSocket service or server) such as Pusher, Soketi or Reverb delivers it.

⚡ ShouldBroadcast goes through the queue

Guess first: an event implementing ShouldBroadcast goes out through the queue (a list of jobs that run later). On the laptop, QUEUE_CONNECTION=database and no php artisan queue:work (the worker, the program that runs the queue) is running. When does Mr. Darto's phone (he owns the order) get the news?

Only once a worker is started. Until then the BroadcastEvent job (the work of sending the message) just waits in the jobs table, with no error. ShouldBroadcastNow sends right away, with no queue.

Meaning: The broadcastWith() method in the event class decides what the message holds, so not all of the order's data is sent.

⚡ Who may listen

Meaning: routes/channels.php decides who may subscribe to a private channel. When the frontend subscribes, the browser sends POST /broadcasting/auth, and Laravel runs that channel's callback with the logged-in user. Mr. Darto, who owns #12, gets 200. Wulan, another customer, gets 403 (refused).

What you will learn