title: Accessing package controllers in Laravel 4
body: <p>I have created a package following the <a href="http://four.laravel.com/docs/packages#creating-a-package" rel="nofollow noreferrer">"Creating a Package" instructions in the Laravel 4 documentation</a>. After creating the package I have created a "controllers" folder and a routes file. The new file structure is:</p>
  
  <pre><code>/src
      /Vendor
          /Package
              PackageServiceProvider.php
      /config
      /controllers
      /lang
      /migrations
      /views
      routes.php
  /tests
  /public
  </code></pre>
  
  <p>I added the routes file to the boot portion of the package service provider:</p>
  
  <pre><code>public function boot()
  {
      $this-&gt;package('vendor/package');
      include __DIR__ . '/../../routes.php';
  }
  </code></pre>
  
  <p>Then added a basic route to the routes file:</p>
  
  <pre><code>Route::get('/package', function() {
      return "Package route test";
  });
  </code></pre>
  
  <p>Visiting my application at the specified route (app.dev/package) returns the expected:</p>
  
  <pre><code>Package route test
  </code></pre>
  
  <p>Then adding a basic controller call to the route (using the default Laravel controller, "HomeController") works:</p>
  
  <pre><code>Route::get('/package', 'HomeController@showWelcome');
  </code></pre>
  
  <p>I then followed <a href="https://stackoverflow.com/a/14667793/200518">this SO answer</a> for setting up the controller for the package. I added the src/controllers folder to the composer classmap, then I dumped the autoloader and checked vendor/composer/autoload_classmap.php and found the class is successfully loaded by composer:</p>
  
  <pre><code>&lt;?php
  
  // autoload_classmap.php generated by Composer
  
  $vendorDir = dirname(__DIR__);
  $baseDir = dirname($vendorDir);
  
  return array(
      'HomeController' =&gt; $baseDir . '/src/controllers/HomeController.php',
  );
  </code></pre>
  
  <p>Now I added the new package controller to the route using the namespace:</p>
  
  <pre><code>Route::get('/package', 'Vendor\Package\Controllers\HomeController@showWelcome');
  </code></pre>
  
  <p>but this produces an error about not finding the class:</p>
  
  <pre><code>ReflectionException: Class Vendor\Package\Controllers\HomeController does not exist
  </code></pre>
  
  <p>I've also tried calling it using the package name:</p>
  
  <pre><code>Route::get('/package', 'Package::HomeController@showWelcome');
  </code></pre>
  
  <p>which produces the same error:</p>
  
  <pre><code>ReflectionException: Class Vendor\Package\Controllers\HomeController does not exist
  </code></pre>
  
  <p>No matter what I try the package cannot access its own controller, which composer confirms is loaded (by viewing vendor/package/autoload_classmap.php).</p>
  
  <p>Any ideas? I'm not sure if the issue is composer not loading the class, I'm not sure where to start with debugging the problem. I've created another package and repeated the steps here and get the same problem. </p>
  
  <p>I can access the package views from both the package and the app, eg:</p>
  
  <pre><code>View::make('package::view');
  </code></pre>
  
  <p>The problem seems to be between composer loading the controller and Laravel being able to access it.</p>