06.10.2016 Views

laravel-5

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Events 350<br />

16 * @param int $podcastId<br />

17 * @return Response<br />

18 */<br />

19 public function purchasePodcast($userId, $podcastId)<br />

20 {<br />

21 $podcast = Podcast::findOrFail($podcastId);<br />

22<br />

23 // Purchase podcast logic...<br />

24<br />

25 Event::fire(new PodcastWasPurchased($podcast));<br />

26 }<br />

27 }<br />

Alternatively, you may use the global event helper function to fire events:<br />

1 event(new PodcastWasPurchased($podcast));<br />

Broadcasting Events<br />

In many modern web applications, web sockets are used to implement real-time, live-updating user<br />

interfaces. When some data is updated on the server, a message is typically sent over a websocket<br />

connection to be handled by the client.<br />

To assist you in building these types of applications, Laravel makes it easy to “broadcast” your events<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 />

¹⁸⁴https://pusher.com

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

Saved successfully!

Ooh no, something went wrong!