注意红色那行的代码,一定要加上这一句!!!
'mongodb_default' => [
'driver' => 'mongodb',
'host' => env('MONGODB_DEFAULT_HOST', 'localhost'),
'port' => env('MONGODB_DEFAULT_PORT', 27017),
'database' => env('MONGODB_DEFAULT_DATABASE'),
'username' => env('MONGODB_DEFAULT_USERNAME'),
'password' => env('MONGODB_DEFAULT_PASSWORD'),
'timezone' => env('DB_TIMEZONE', '+08:00'),
'options' => [
// here you can pass more settings to the Mongo Driver Manager
// see https://www.php.net/manual/en/mongodb-driver-manager.construct.php under "Uri Options" for a list of complete parameters that you can use
'database' => env('MONGODB_DEFAULT_DATABASE'), // required with Mongo 3+
],
],
另外还有一点
和lumen结合时候
$app->withEloquent();
一定要写在
$app->register(JenssegersMongodbMongodbServiceProvider::class);
后面
否则会报Unsupported driver [mongodb].的错误