Laravel Echo is a JavaScript library that simplifies subscribing to channels and listening for events broadcast by a Laravel application. It is primarily used for building real-time web applications and integrates seamlessly with broadcasting services like Pusher or Redis.
Laravel Echo was introduced to complement Laravel's broadcasting capabilities, providing a simple and expressive API for front-end developers to handle real-time updates.
Install Laravel Echo and a WebSocket driver (e.g., Pusher):
npm install --save laravel-echo pusher-js
Configure Echo in your JavaScript application:
import Echo from 'laravel-echo';
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'your-pusher-key',
cluster: 'mt1',
forceTLS: true
});
Listen for events on a channel:
Echo.channel('orders')
.listen('OrderShipped', (e) => {
console.log('Order shipped:', e.order);
});
Laravel Echo simplifies real-time web application development by bridging the gap between back-end broadcasting and front-end event handling.