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 252<br />

.<br />

13<br />

14 public $user;<br />

15<br />

16 /**<br />

17 * Create a new event instance.<br />

18 *<br />

19 * @return void<br />

20 */<br />

21 public function __construct(User $user)<br />

22 {<br />

23 $this->user = $user;<br />

24 }<br />

25<br />

26 /**<br />

27 * Get the channels the event should be broadcast on.<br />

28 *<br />

29 * @return array<br />

30 */<br />

31 public function broadcastOn()<br />

32 {<br />

33 return ['user.'.$this->user->id];<br />

34 }<br />

35 }<br />

Then, you only need to fire the event as you normally would. Once the event has been fired, a<br />

queued job will automatically broadcast the event over your specified broadcast driver.<br />

Broadcast Data<br />

When an event is broadcast, all of its public properties are automatically serialized and broadcast as<br />

the event’s payload, allowing you to access any of its public data from your JavaScript application.<br />

So, for example, if your event has a single public $user property that contains an Eloquent model,<br />

the broadcast payload would be:<br />

.<br />

1 {<br />

2 "user": {<br />

3 "id": 1,<br />

4 "name": "Jonathan Banks"<br />

5 ...

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

Saved successfully!

Ooh no, something went wrong!