🔴 Laravel
Intermediate
What is Broadcasting in Laravel?
Answer
Broadcasting allows server-side events to be sent to the browser in real-time via WebSockets. Laravel supports Pusher, Ably, Laravel WebSockets (self-hosted), and Soketi. Make an event broadcastable by implementing ShouldBroadcast and define the channel in broadcastOn(): return new Channel("orders.{$this->order->id}"). On the frontend, subscribe with Laravel Echo: Echo.channel("orders.1").listen("OrderShipmentStatusUpdated", (e) => { ... }). Private channels require authentication (defined in routes/channels.php): Broadcast::channel("orders.{orderId}", fn($user, $orderId) => $user->id === Order::find($orderId)->user_id). Broadcasting enables live notifications, chat features, real-time dashboards, and collaborative editing.