title: Call to a member function connection() on null error in Slim using Laravel's Eloquent ORM
body: <p>I'm trying to make use of Laravel's Eloquent ORM on Slim microframework, but I've been seeing the error: Call to a member function connection() on null</p>
  
  <p>Here is the code: </p>
  
  <p><strong>dependency.php</strong></p>
  
  <pre><code>$container['db'] = function($container) {
      $capsule = new \Illuminate\Database\Capsule\Manager;
      $capsule-&gt;addConnection($container-&gt;get('settings')['database']);
  
      $capsule-&gt;setAsGlobal();
      $capsule-&gt;bootEloquent();
  
      return $capsule;
  };
  </code></pre>
  
  <p><strong>User.php (Model class)</strong></p>
  
  <pre><code>use Illuminate\Database\Eloquent\Model as Model;
  
  class User extends Model {
  
      protected $table = "users";
  
      protected $fillable = ['name', 'email', 'password'];
  }
  </code></pre>
  
  <p><strong>HomeController.php (Controller class)</strong></p>
  
  <pre><code>class Home extends Controller {
  
  public function index($request, $response, $args) {
          $user = User::find(1);
          var_dump($user);
          die();
          $title = "Slim Auth";
          $response = $this-&gt;view-&gt;render($response, 'home.php', ["title" =&gt; $title]);
          return $response;
      }
  }
  </code></pre>
  
  <p>dependency.php was required into my bootstrap.php file where the Slim class was instantiated thus:</p>
  
  <pre><code>$config = [
      'settings' =&gt; [
          'displayErrorDetails' =&gt; true,
  
          'view' =&gt; [
              'view_path' =&gt; APP_PATH . 'views/'
          ],
  
          'database' =&gt; [
              'driver'    =&gt; 'mysql',
              'host'      =&gt; 'localhost',
              'database'  =&gt; 'tutorial_slim_auth',
              'username'  =&gt; 'root',
              'password'  =&gt; 'passw0rd',
              'charset'   =&gt; 'utf8',
              'collation' =&gt; 'utf8_unicode_ci',
              'prefix'    =&gt; '',
          ],
      ]
  ];
  
  $app = new Slim\App($config);
  </code></pre>
  
  <p>while HomeController.php and User.php were autoloaded via composer json file. After running the index.php (which also included my bootstrap.php) file containing:</p>
  
  <pre><code>$app-&gt;run();
  </code></pre>
  
  <p>this gave me a fatal error:  Call to a member function connection() on null.
  But doing this:</p>
  
  <pre><code>echo '&lt;pre&gt;';
  print_r($container['db']);
  echo '&lt;/pre&gt;';
  </code></pre>
  
  <p>in my bootstrap file produced the expected result along with the result of the var_dump function called in the HomeController.php file. What do I do? Or is there anything I'm not doing right?</p>