PHP Lumen Call to a member function connection() on null PHP Lumen Call to a member function connection() on null laravel laravel

PHP Lumen Call to a member function connection() on null


You should uncomment the Eloquent $app->withEloquent() call in bootstrap/app.php.

https://lumen.laravel.com/docs/5.2/database#basic-usage

Update:

Latest version of the docs https://lumen.laravel.com/docs/5.8/database, check section Eloquent ORM


As per 2021 here is the check list to check against to fix this error.

You have to:

  1. Create the database manually via e.g. PHPMyAdmin;
  2. Configure the database connection it in the .env file (i.e. set DB_CONNECTION, DB_DATABASE, DB_USERNAME, DB_PASSWORD);
  3. As per above answers uncomment $app->withFacades();, $app->withEloquent(); lines in bootstrap/app.php;
  4. If you use your Eloquent model within PHPUnit tests you have to boot the Lumen (or Laravel) first by adding the following line to your test class setUp() method:
    parent::setUp()

That should fix it.


I think you just uncomment $app->withFacades();, $app->withEloquent(); lines in bootstrap/app.php;

And check again, it works for me.