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:
- Create the database manually via e.g. PHPMyAdmin;
- Configure the database connection it in the
.env
file (i.e. setDB_CONNECTION
,DB_DATABASE
,DB_USERNAME
,DB_PASSWORD
); - As per above answers uncomment
$app->withFacades();
,$app->withEloquent();
lines inbootstrap/app.php
; - 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.