在Laravel外独立使用laravel-mongodb

laravel框架外部使用laravel-mongodb 插件

下载安装方式主要根据github上的参考:

https://github.com/jenssegers/laravel-mongodb#installation

参考一:

安装

Installation using composer:

composer require jenssegers/mongodb
Or
composer require jenssegers/mongodb:*
 
The service provider will register a mongodb database extension with the original database manager. There is no need to register additional facades or objects. When using mongodb connections, Laravel will automatically provide you with the corresponding mongodb objects.

For usage outside Laravel, check out the Capsule manager and add:

在Laravel外独立使用不需要注册,先预加载Capsule manager,然后添加如下代码 $capsule
->getDatabaseManager()->extend('mongodb', function($config) { return new Jenssegers\Mongodb\Connection($config); });

###该段代码不添加会报错: Uncaught exception 'InvalidArgumentException' with message 'Unsupported driver [mongodb]' 

安装后可能会出现问题:
Fatal error: Class 'MongoClient' not found

这个是因为composer安装后有mongo,mongodb,就是laravel-mongodb 支持2个都支持,php 也同时支持mongo,mongodb
详见:http://php.net/MongoClient
如果确认你安转了 mongodb

    检测方法:
    cli;
    php -m | grep mongo
    php -i | grep 'Mongo'

检测/vendor/composer/install.json

mongo 去掉,composer update ,composer install 搞定

 
 
 


猜你喜欢

转载自www.cnblogs.com/cbugs/p/10081461.html