Realtime features — live notifications, chat, an online-users list — are built in Laravel with broadcasting. In Laravel 12 the official WebSocket server is Reverb, and the browser side uses Laravel Echo.
Architecture: event → Reverb → Echo
PHP code creates an event, it passes through the queue to Reverb, and Reverb sends it to subscribed browsers. PHP itself never holds the WebSocket connection.
Installation
One command sets everything up: the Reverb package, config/broadcasting.php, routes/channels.php and the JavaScript side.
php artisan install:broadcasting
php artisan reverb:start --debug
php artisan queue:listen
npm run devThe key values in .env:
BROADCAST_CONNECTION=reverb
REVERB_APP_ID=local-app
REVERB_APP_KEY=local-key
REVERB_APP_SECRET=local-secret
REVERB_HOST="localhost"
REVERB_PORT=8080
REVERB_SCHEME=http
VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
VITE_REVERB_HOST="${REVERB_HOST}"
VITE_REVERB_PORT="${REVERB_PORT}"
VITE_REVERB_SCHEME="${REVERB_SCHEME}"💡 The
--debugflag prints every connection and message in the terminal, which is handy during development.
Writing a broadcast event
The event implements the ShouldBroadcast interface and returns the channel from broadcastOn(). broadcastAs() and broadcastWith() are optional: they set the name and the payload.
<?php
namespace App\Events;