Laravel Broadcasting provides real-time capabilities to Laravel applications, allowing events to be broadcast to clients using WebSockets. It integrates with services like Pusher and Redis to enable real-time features like notifications, chat systems, and live updates.
Broadcasting was introduced in Laravel to facilitate real-time communication by integrating server-side events with front-end frameworks.
Install a WebSocket driver (e.g., Pusher):
composer require pusher/pusher-php-server
Configure broadcasting in .env
:
BROADCAST_DRIVER=pusher
Broadcast an event:
use App\Events\OrderShipped;
OrderShipped::dispatch($order);
Listen to the event on the front-end using Laravel Echo:
Echo.channel('orders')
.listen('OrderShipped', (e) => {
console.log(e.order);
});
Laravel Broadcasting bridges the gap between server-side events and client-side real-time updates.