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.

HTTP Controllers 144<br />

11 */<br />

12 protected $users;<br />

13<br />

14 /**<br />

15 * Create a new controller instance.<br />

16 *<br />

17 * @param UserRepository $users<br />

18 * @return void<br />

19 */<br />

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

21 {<br />

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

23 }<br />

24 }<br />

Of course, you may also type-hint any Laravel contract. If the container can resolve it, you can<br />

type-hint it.<br />

Method Injection<br />

In addition to constructor injection, you may also type-hint dependencies on your controller’s action<br />

methods. For example, let’s type-hint the Illuminate\Http\Request instance on one of our methods:<br />

1

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

Saved successfully!

Ooh no, something went wrong!