Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nickclicksco's avatar

Getting Laravel and Homestead to work with MongoDB

Hi all, I'm getting a quite frustrated by how hard it seems to be to set up MongoDB with Laravel.

So far I have installed the MongoDB composer package to my project:

https://packagist.org/packages/mongodb/mongodb

I have also added my database credentials to my .env file.

Then I tried testing it out by adding this to my web.php route file:

use MongoDB\Client as Mongo;
Route::get('mongo', function(Request $request) {
    $collection = (new Mongo)->mydatabase->mycollection;
    return $collection->find()->toArray();
});

This didn't work as when I visited /mongo I got this error:

 Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
Class 'MongoDB\Driver\Manager' not found

I'm a little bit confused to how I get this to work, do I need to install it on to homestead and if so how do I do this?

Thanks

0 likes
5 replies
nickclicksco's avatar

@topvillas Do you mean on homestead itself? I haven't installed anything apart from the composer package.

Please or to participate in this conversation.