29.07.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 248<br />

.<br />

28 {<br />

29 // Access the podcast using $event->podcast...<br />

30 }<br />

31 }<br />

Your event listeners may also type-hint any dependencies they need on their constructors. All<br />

event listeners are resolved via the Laravel service container, so dependencies will be injected<br />

automatically:<br />

.<br />

1 use Illuminate\Contracts\Mail\Mailer;<br />

2<br />

3 public function __construct(Mailer $mailer)<br />

4 {<br />

5 $this->mailer = $mailer;<br />

6 }<br />

Stopping The Propagation Of An Event<br />

Sometimes, you may wish to stop the propagation of an event to other listeners. You may do so by<br />

returning false from your listener’s handle method.<br />

Queued Event Listeners<br />

Need to queue an event listener? It couldn’t be any easier. Simply add the ShouldQueue interface to<br />

the listener class. Listeners generated by the event:generate Artisan command already have this<br />

interface imported into the current namespace, so you can use it immediately:<br />

.<br />

1

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

Saved successfully!

Ooh no, something went wrong!