Jens Segers on

Combining Laravel and MongoDB

Unfortunately, Laravel 4 has no native support for Mongo databases. Once I started searching for open source Mongo packages on GitHub, I was disappointed that not one package was able to seamlessly integrate a Mongo database driver into Laravel 4. Every single package I found had an entirely different interface for the Query Builder and Eloquent models, which meant that I had to rewrite all of my existing code, just because I wanted to use a different database driver.

Laravel 4 and MongoDB

Therefor, I decided to write one myself, which is now called Moloquent by the community. The package I wrote depends on the existing Laravel 4 database component and extends the original classes. This means I am forced to respect the original methods and interfaces. Because most of the query translation is done by the Query Builder, a lot of Eloquent methods just work without having to modify the actual class.

After installing the package using composer, you only need to register a service provider that will add the Mongo database driver as an extension with the original database manager. More detailed installation instructions and documentation can be found at github.com/jenssegers/Laravel-MongoDB. Some functionality may not be working at this moment, so feel free to contribute.

Webmentions

Tweet about this blog post and you will appear below!