I'm trying to wrap my head around dependency injection and the IoC container and i'm using my UserController as an example. I'm defining what the UserController depends on in its constructor and then am binding those objects to it using App::bind(). If i'm using the Input::get() facade/method/thing am i not taking advantage of the Request object i just injected into it? Should i be using the following code instead, now that the Request object is injected or doesInput::get() resolve to the same Request instance? I'd like to use the static facades but not if they resolve to un-injected objects.
$this->request->get('email');
Dependency injection
<?php
App::bind('UserController', function() {
$controller = new UserController(
new Response,
App::make('request'),
App::make('view'),
App::make('validator'),
App::make('hash'),
new User
);
return $controller;
});
UserController
<?php
class UserController extends BaseController {
protected $response;
protected $request;
protected $validator;
protected $hasher;
protected $user;
protected $view;
public function __construct(
Response $response,
\Illuminate\Http\Request $request,
\Illuminate\View\Environment $view,
\Illuminate\Validation\Factory $validator,
\Illuminate\Hashing\BcryptHasher $hasher,
User $user
){
$this->response = $response;
$this->request = $request;
$this->view = $view;
$this->validator = $validator;
$this->hasher = $hasher;
$this->user = $user;
}
public function index()
{
//should i use this?
$email = Input::get('email');
//or this?
$email = $this->request->get('email');
//should i use this?
return $this->view->make('users.login');
//or this?
return View::make('users.login');
}