Broadcasting
Introduction
In many modern web applications, WebSockets are used to implement realtime, live-updating user interfaces. When some data is updated on the server, a message is typically sent over a WebSocket connection to be handled by the client. This provides a more robust, efficient alternative to continually polling your application for changes.
To assist you in building these types of applications, Laravel makes it easy to "broadcast" your events over a WebSocket connection. Broadcasting your Laravel events allows you to share the same event names between your server-side code and your client-side JavaScript application.
Before diving into event broadcasting, make sure you have read all of the documentation regarding Laravel events and listeners.
Configuration
All of your application's event broadcasting configuration is stored in the config/broadcasting.php
configuration file. Laravel supports several broadcast drivers out of the box: Pusher Channels, Redis, and a log
driver for local development and debugging. Additionally, a null
driver is included which allows you to totally disable broadcasting. A configuration example is included for each of these drivers in the config/broadcasting.php
configuration file.
Broadcast Service Provider
Before broadcasting any events, you will first need to register the App\Providers\BroadcastServiceProvider
. In fresh Laravel applications, you only need to uncomment this provider in the providers
array of your config/app.php
configuration file. This provider will allow you to register the broadcast authorization routes and callbacks.