29.07.2016 Views

laravel-5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Events 251<br />

over a websocket connection. Broadcasting your Laravel events allows you to share the same event<br />

names between your server-side code and your client-side JavaScript framework.<br />

Configuration<br />

All of the event broadcasting configuration options are stored in the config/broadcasting.php<br />

configuration file. Laravel supports several broadcast drivers out of the box: Pusher¹⁵¹, Redis, and a<br />

log driver for local development and debugging. A configuration example is included for each of<br />

these drivers.<br />

Broadcast Prerequisites<br />

The following dependencies are needed for event broadcasting:<br />

• Pusher: pusher/pusher-php-server ∼2.0<br />

• Redis: predis/predis ∼1.0<br />

Queue Prerequisites<br />

Before broadcasting events, you will also need to configure and run a queue listener. All event<br />

broadcasting is done via queued jobs so that the response time of your application is not seriously<br />

affected.<br />

Marking Events For Broadcast<br />

To inform Laravel that a given event should be broadcast, implement the Illuminate\Contracts\Broadcasting\Sho<br />

interface on the event class. The ShouldBroadcast interface requires you to implement a single<br />

method: broadcastOn. The broadcastOn method should return an array of “channel” names that<br />

the event should be broadcast on:<br />

.<br />

1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!