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.

Service Container 198<br />

20 public function __construct(UserRepository $users)<br />

21 {<br />

22 $this->users = $users;<br />

23 }<br />

24<br />

25 /**<br />

26 * Show the user with the given ID.<br />

27 *<br />

28 * @param int $id<br />

29 * @return Response<br />

30 */<br />

31 public function show($id)<br />

32 {<br />

33 //<br />

34 }<br />

35 }<br />

Container Events<br />

The service container fires an event each time it resolves an object. You may listen to this event<br />

using the resolving method:<br />

1 $this->app->resolving(function ($object, $app) {<br />

2 // Called when container resolves object of any type...<br />

3 });<br />

4<br />

5 $this->app->resolving(FooBar::class, function (FooBar $fooBar, $app) {<br />

6 // Called when container resolves objects of type "FooBar"...<br />

7 });<br />

As you can see, the object being resolved will be passed to the callback, allowing you to set any<br />

additional properties on the object before it is given to its consumer.

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

Saved successfully!

Ooh no, something went wrong!