Live features, such as seeing a driver move on a map, a notification appearing without a refresh, or a chat message arriving instantly, all come down to the same thing: the server pushes an event to the browser instead of the browser asking again and again. Laravel's broadcasting layer with Pusher makes that straightforward. I will use live ride tracking as the running example.

How the pieces fit

Your Laravel app fires an event. Broadcasting sends it to Pusher (a hosted WebSocket service). The browser, connected to Pusher through Laravel Echo, receives it and updates the page. Your PHP never holds open a socket, so it keeps behaving like a normal request-response app.

Install and configure

On current Laravel versions, one command sets up broadcasting and the client dependencies.

php artisan install:broadcasting
npm install --save-dev laravel-echo pusher-js

Then add your Pusher credentials to .env:

BROADCAST_CONNECTION=pusher
PUSHER_APP_ID=...
PUSHER_APP_KEY=...
PUSHER_APP_SECRET=...
PUSHER_APP_CLUSTER=ap2

Create a broadcast event

An event that implements ShouldBroadcast is pushed automatically when it is dispatched. Keep the payload small: ids and the few values the UI needs, not whole models.

class DriverLocationUpdated implements ShouldBroadcast
{
    public function __construct(
        public int $rideId,
        public float $lat,
        public float $lng,
    ) {}

    public function broadcastOn(): array
    {
        return [new PrivateChannel("rides.{$this->rideId}")];
    }

    public function broadcastAs(): string
    {
        return 'location.updated';
    }
}

// when the driver app reports a position
DriverLocationUpdated::dispatch($ride->id, $lat, $lng);

By default this goes through the queue, so the request that reports the location returns immediately. Use ShouldBroadcastNow only when you genuinely need it to skip the queue.

Protect private channels

A private channel is only as private as its authorization rule. Define who may listen, and make the rule specific: here, only the rider and driver of that ride.

// routes/channels.php
Broadcast::channel('rides.{rideId}', function (User $user, int $rideId) {
    return Ride::whereKey($rideId)
        ->where(fn ($q) => $q->where('rider_id', $user->id)->orWhere('driver_id', $user->id))
        ->exists();
});

Listen with Laravel Echo

Configure Echo once, then subscribe to the channel for the current ride. Because the event sets a custom name with broadcastAs, the listener name starts with a dot.

import Echo from 'laravel-echo';
import Pusher from 'pusher-js';

window.Pusher = Pusher;
window.Echo = new Echo({
    broadcaster: 'pusher',
    key: import.meta.env.VITE_PUSHER_APP_KEY,
    cluster: import.meta.env.VITE_PUSHER_APP_CLUSTER,
    forceTLS: true,
});

Echo.private(`rides.${rideId}`)
    .listen('.location.updated', ({ lat, lng }) => {
        driverMarker.setPosition({ lat, lng });
    });

Presence, notifications and chat

The same machinery covers the other common features. A presence channel tells you who is currently online, which is handy for showing whether a driver is available. Notifications can be broadcast to a private per-user channel, and a chat room is a channel where each message is an event. Nothing new to learn, just different channel types.

Keep it from falling over

  • Throttle high-frequency updates. A phone can report its location every second. Broadcast every few seconds, or only when the position changes meaningfully, to save messages and battery.
  • Make the UI resilient. Connections drop on mobile networks. Refetch the latest state on reconnect rather than assuming no event was missed.
  • Run queue workers. Broadcasts are queued jobs, so a stopped worker means silent clients. Monitor it with Supervisor and alert on queue depth.
  • Never trust the client. Events flow from the server to the browser. Anything the browser sends back still goes through normal validated, authorized requests.
  • Mind the limits. Pusher plans cap concurrent connections and daily messages, so check them against your expected traffic. If you outgrow them, Laravel Reverb is a self-hosted alternative that works with the same Echo client, just with a different broadcaster setting.

Wrap up

Broadcasting is a small amount of code for a big jump in how alive an app feels: an event class, a channel rule and a listener. Start with one feature, such as a single live status, get the authorization and queue worker right, and the rest follows the same pattern.