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:
- public: anyone may listen.
- private: a listener must show an ID card at the desk first. The ID card is the login, and the desk that checks it is
routes/channels.php. - presence: private, plus a list of who is there right now.
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?
ShouldBroadcastmeans the event goes out through the queue (a list of jobs that run later). Laravel makes a job (one piece of work) calledBroadcastEvent, and only sends the message when a worker,php artisan queue:work, runs that job. Without a worker, the job just waits in thejobstable, and Mr. Darto's phone receives nothing. The news arrives only once a worker is started.ShouldBroadcastNowsends right away, with no queue.broadcastOn()picks the channel. For order #12,new PrivateChannel('orders.12')becomes a channel namedprivate-orders.12, becausePrivateChanneladds theprivate-prefix.broadcastWith()decides what the message holds. WithoutbroadcastWith(), every public property of the event is sent, including the wholeOrdermodel (phone number and all).- The event's name is the full class name,
App\Events\OrderStatusChanged, unless you give it another name withbroadcastAs(). - If the event is dispatched inside a database transaction (several changes saved together, or not at all), add
ShouldDispatchAfterCommit. Then the message does not go out before the data is really saved.
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;
});
- When the frontend subscribes to
private-orders.12, Echo (Laravel's JavaScript library for listening to channels) sendsPOST /broadcasting/authwithsocket_idandchannel_name. Laravel runs theorders.{order}callback with the logged-in user. Mr. Darto (who owns #12) gets200with a signature{"auth":"<key>:<hmac>"}, which Echo then shows the WebSocket server as proof of permission. Wulan, another customer, gets403(refused). A user who is not logged in is refused right away, and the callback never runs. - The callback of a presence channel (
new PresenceChannel('board'), namedpresence-board) returns an array of user data, nottrue: here a staff member'sidandname, which appear in the list of who is present. Other users getnull, so they are refused. Echo gives the list of who is present throughhere, then who arrives throughjoiningand who leaves throughleaving. php artisan channel:listshows every registered callback.
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
REVERB_APP_ID,REVERB_APP_KEY,REVERB_APP_SECRET: the app's credentials (proof of identity).REVERB_HOST/REVERB_PORT: where Laravel sends events.REVERB_SERVER_HOST/REVERB_SERVER_PORT: where the Reverb server itself listens.allowed_originsinconfig/reverb.phplimits which pages may connect (the Origin check, WebSocket Authentication lesson).- For several Reverb servers, set
REVERB_SCALING_ENABLED=true. They then pass messages to each other through Redis Pub/Sub.
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
})
Echo.private('orders.12')subscribes toprivate-orders.12, and calls/broadcasting/authby itself..listen('OrderStatusChanged')can use the short name. Echo adds the default namespaceApp.Eventsin front of it (a namespace here is the first part of a PHP class name, not a Socket.IO namespace). So the name it looks for isApp\Events\OrderStatusChanged(checked in the laravel-echo 2.6.1 code). If the event uses abroadcastAs()that returns'order.status', listen for'.order.status', with a leading dot, which tells Echo not to add the namespace.- In React:
useEcho('orders.12', 'OrderStatusChanged', (e) => ...)from@laravel/echo-react.useEcholeaves the channel by itself when its component unmounts (is removed from the screen).
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
- Forgetting to run
queue:work.ShouldBroadcastgoes through the queue. No worker means no news, and no error either. broadcastAs()but.listen()without the dot. Echo addsApp\Events\in front of the name, then looks for a name that is never sent.- Sending the whole model. Every public property is sent. Use
broadcastWith(). - Forgetting the Redis prefix. Node subscribes to
private-orders.12, while Laravel publishes tolaundry-database-private-orders.12. - The sender gets its own news back. For example, Eko's tablet also listens to
private-orders.12, and has already updated its screen from the response to its own request. The same news then arrives again through the channel, so the change shows twice. Send it withbroadcast(new OrderStatusChanged($order))->toOthers(): the news is not sent to the connection whose id matches theX-Socket-IDheader of that request, which is Eko's tablet. The event must useInteractsWithSockets(the example above does). A global Axios (an HTTP request library for the whole page) sends that header automatically once Echo is created. Withfetch, add it yourself:headers: { 'X-Socket-ID': Echo.socketId() }.
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).