title: Laravel Controller Dependency Injection
body: <p>I'm trying to do dependency injection in Laravel to keep my controllers and models as slim as possible. The goal is to have repositories to handle the fetching of data attributed to certain models.</p>
  
  <p>To this end I'm trying to follow the example from the documentation <strong><a href="https://laravel.com/docs/5.0/controllers#dependency-injection-and-controllers" rel="noreferrer">here</a></strong> and a popular Laravel boilerplate <strong><a href="https://github.com/rappasoft/laravel-5-boilerplate/" rel="noreferrer">here</a></strong></p>
  
  <p>But I don't understand where the <code>$user</code> is coming from. </p>
  
  <p>So looking at the boilerplate we have two files:</p>
  
  <p>The <code>ProfileController</code> <strong><a href="https://github.com/rappasoft/laravel-5-boilerplate/blob/c5f7d95f11c584a9ed2446fa28174fb068257e62/app/Http/Controllers/Frontend/User/ProfileController.php" rel="noreferrer">here</a></strong></p>
  
  <p>Excerpt below:</p>
  
  <pre><code>use App\Repositories\Frontend\Access\User\UserRepository;
  /**
   * Class ProfileController.
   */
  class ProfileController extends Controller
  {
      /**
       * @var UserRepository
       */
      protected $user;
      /**
       * ProfileController constructor.
       *
       * @param UserRepository $user
       */
      public function __construct(UserRepository $user)
      {
          $this-&gt;user = $user;
      }
  </code></pre>
  
  <p>This looks a lot  like the dependency injection mentioned in the docs, which is this:</p>
  
  <pre><code>class UserController extends Controller {
  
       /**
           * The user repository instance.
           */
          protected $users;
  
          /**
           * Create a new controller instance.
           *
           * @param  UserRepository  $users
           * @return void
           */
          public function __construct(UserRepository $users)
          {
              $this-&gt;users = $users;
          }
  </code></pre>
  
  <p>My problem is I don't understand where the <code>$user</code> is coming from.</p>
  
  <p>In the <strong><a href="https://github.com/rappasoft/laravel-5-boilerplate/blob/341da70e0dd5eef0944acb13799b145b9df1de85/app/Repositories/Frontend/Access/User/UserRepository.php" rel="noreferrer">UserRepository</a></strong> there is no $user defined as a parameter of the class itself. No where in the code is there any <code>Auth::user()</code> so I'm confused as to where the user instance is coming from.</p>