title: How can I do constructor-injected dependencies in Laravel 4?
body: <p>My team likes the idea of constructor-injected dependencies because it makes deps very clear when looking at a class. With the use of the facades, I'm aware they can be mocked and <code>swap</code>ped, but one would have to examine every line of a class to figure out what it depends on! I discovered that I could find the true class behind the facade with, for instance, <code>Form::getFacadeRoot()</code>.</p>
  
  <p>The controller code that I've ended up with is:</p>
  
  <pre><code>use Illuminate\Html\FormBuilder as Form;
  use Illuminate\Validation\Factory as Validator;
  use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage as Session;
  use Illuminate\Http\Request as Input;
  use Illuminate\Routing\Redirector as Redirect;
  use Illuminate\View\Environment as View;
  
  class HomeController extends BaseController {
  
      protected $form;
      protected $validator;
      protected $session;
      protected $input;
      protected $redirect;
      protected $view;
  
      protected $layout = 'layouts.master';
  
      protected $validationRules = array(
          'name'  =&gt; array('required', 'min:3'),
          'email' =&gt; array('required', 'regex:/^.+@.+\..{2,4}$/')
      );
  
      public function __construct(Form $form, Validator $validator, Session $session,
          Input $input, Redirector $redirect, View $view
      ) {
          $this-&gt;form      = $form;
          $this-&gt;validator = $validator;
          $this-&gt;session   = $session;
          $this-&gt;input     = $input;
          $this-&gt;redirect  = $redirect;
          $this-&gt;view      = $view;
      }
  
          ...
  }
  </code></pre>
  
  <p>When my test does <code>$this-&gt;client-&gt;request('Get', '/');</code>, it errors out:</p>
  
  <pre><code>Illuminate\Container\BindingResolutionException: Unresolvable dependency resolving [Parameter #2 [ &lt;required&gt; $csrfToken ]].
  </code></pre>
  
  <p>Am I on even close to the right track here? I'm sort of making this up as I go along because I don't see much discussion on this issue. Feel free to comment on my reason for even trying; I could be sold on facades, yet.</p>
  
  <p>Thanks !</p>