Use MongoDB in the Laravel framework, provided you have installed the MongoDB and MongoDB PHP extensions.
Not installed, specific can refer to the blog http://blog.csdn.net/turtleo/article/details/50119459
1, the use of composer in the Laravel framework to introduce MongoDB
Composer require Jenssegers/mongodb
2. Edit config/app.php file
Add the following code in the providers
Jenssegers\mongodb\mongodbserviceprovider::class,
Add the following code in the aliases
' Mongo ' => jenssegers\mongodb\mongodbserviceprovider::class,
3. Configure config/database.php
' Default ' => env (' Db_connectiond ', ' MongoDB ')
' MongoDB ' => [
' driver ' => ' MongoDB ',
' host ' => ' localhost ',
' Port ' => 27017,
' database ' => ' test ',
' username ' => ',
' password ' =>
',
4, the test configuration is correct
Create a new model file
<?php
namespace App;
Use Mongo;
Use DB;
Class Mongodb extends Mongo {
protected $collection = ' users ';
Protected $connection = ' test ';
public static function test () {
$users = db::collection (' users ')->get ();
Var_dump ($users);
}
Create a new controller file
<?php
namespace App\http\controllers;
Use App\http\controllers\controller;
Use App\mongodb;
Class Mongodbcontroller extends controller{
protected function test () {
mongodb::test ();
}
}