Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
759 views
in Technique[技术] by (71.8m points)

laravel - Class 'MongoDBDriverManager' not found

I'm integrating MongoDB with Laravel. I'm following information found in this link jenssegers/laravel-mongodb. I'm successful at integrating MongoDB. But when I run the code it throws this error

FatalErrorException in Client.php line 56: Class 'MongoDBDriverManager' not found

Here is the code

Controller app/Http/Controller/NewController

<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;

use AppHttpRequests;

use AppUser;

class NewController extends Controller
{
    //
    public function index(){
        $var = User::all();
        var_dump($var);
    }
}

And here follows the user.php that is by default provided by Laravel when we create the project

<?php

namespace App;

use IlluminateFoundationAuthUser as Authenticatable;
use JenssegersMongodbEloquentModel as Eloquent;

class User  extends Eloquent 
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $collection = 'users_collection';
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
}

Please tell me why am I getting this error.

Phpinfo --> mongodb section is coming. Here is a screen shot phpinfo

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I do not know if it's the most elegant solution, but it worked for me:

  1. Install the php driver $ sudo pecl install mongodb
  2. Create the extension file $ sudo nano /etc/php5/mods-available/mongodb.ini and write inside: extension=mongodb.so
  3. Create a symbolic link for this file $ sudo ln -sv /etc/php5/mods-available/mongodb.ini /etc/php5/apache2/conf.d/20-mongodb.ini
  4. Create an other symbolic link for this file $ sudo ln -sv /etc/php5/mods-available/mongodb.ini /etc/php5/cli/conf.d/20-mongodb.ini
  5. Restart apache or the server used $ sudo service apache2 restart

It may be necessary to reinstall jenssegers/mongodb: $ composer require jenssegers/mongodb


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...