Php framework laravel5.1 mongodb database Simple example

Source: Internet
Author: User
Tags install mongodb mongodb php framework php mongodb

I. INTRODUCTION to mongodb installation in the previous section

Installing php mongodb with macos

2: laravel5.1 installation process http://www.golaravel.com/laravel/docs/5.1/#installation

III. laravel5.1 install mongodb

Composer require jenssegers/mongodb



 

Create a file in app/mongodb. php

<? Php
 
Namespace App;
 
Use Jenssegers \ Mongodb \ Model as Eloquent;
Use Illuminate \ Database \ Eloquent \ Model;
Class Mongodb extends Eloquent {
 
Protected $ connection = 'mongodb ';
Protected $ collection = 'admin ';
 
}

Add the mongodb link in config/database. php

'Mongodb '=> [
'Driver '=> 'mongodb ',
'Host' => env ('Mo _ DB_HOST ', '192. 168.33.10 '),
'Port' => env ('Mo _ DB_PORT ', 27017 ),
'Database' => env ('Mo _ DB_DATABASE ', 'admin '),
'Username' => env ('Mo _ db_username', 'tank '),
'Password' => env ('Mo _ DB_PASSWORD ', 'test '),
'Options' => array (
'DB' => 'admin' // sets the authentication database required by mongo 3
)
],

Add a route entry in app/Http/routes. php

Route: get ('/mongodb', function (){
$ User = \ App \ Mongodb: all ();
 
Print_r ($ user );
 
});


Finally, access http: // localhost/laravel5.1/mongo locally.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.