mawelous / yamop-laravel by kamilz

Yet another MongoDB ODM for PHP as Laravel Component. Nothing unnecessary, with easy joins.
Package Data
Maintainer Username: kamilz
Maintainer Contact: (Kamil Zieliński)
Package Create Date: 2013-06-10
Package Last Update: 2016-03-01
Language: PHP
License: MIT
Last Refreshed: 2023-05-30 15:20:36
Package Statistics
Total Downloads: 151
Monthly Downloads: 1
Daily Downloads: 0
Total Stars: 8
Total Watchers: 8
Total Forks: 1
Total Open Issues: 0

Yamop for Laravel

Yet another MongoDB ODM for PHP as Laravel Component

What's that?

This is yet another, open source, and very simple MongoDB ODM for Laravel 4. It works like the standard MongoDB PHP extension interface but returns objects instead of arrays (as ODM). Queries stay the same. One of its coolest features are joins which allow you to query for related objects. This version for Laravel is based on Yamop which can be included into any PHP project. In addition to the standard features it supports Laravel based authentication.


  • PHP 5.3+
  • PHP MongoDB Extension
  • Laravel 4


You can simply download it here or use Composer.

In the require key inside the composer.json file add the following

    "mawelous/yamop-laravel": "dev-master"

Save it and run the Composer update command

$ composer update

After this is done, add mongo in your database configuration:

    'mongo' => array(
        'host'     => 'host',
        'port'     => 37847,
        'database' => 'db',
        'user'     => 'user',
        'password' => 'pass'

Now we need to let Laravel know about this new service provider. To do so add under providers in the config\app.php file the following:


Aliases to the Yamop classes are useful. Add them in the aliases array in the config\app.php file:

    'Validator'       => 'Illuminate\Support\Facades\Validator',
    'View'            => 'Illuminate\Support\Facades\View',
    'Mapper'          => 'Mawelous\YamopLaravel\Mapper',
    'Model'           => 'Mawelous\YamopLaravel\Model',

To use Yamop you now just need to extend the Yamop alias Model from within any of your new or existing models:

    class Article extends Model
        protected static $_collectionName = 'articles';

That's it!


For usage examples and further explanation take a look at the Yamop Documentation. In this release for Laravel you can also use aliases for Mapper and Model which were registered during installation. See the following pagination example.


Yamop for Laravel supports pagination out of the box. It implements the _createPaginator method and extends getPaginator, with this you only need to pass the items per page into the method. The second parameter which is the current page number, and the third which is the page parameter name are both optional.

        ->find( 'status' => [ '$ne' => User::STATUS_DELETED ] ) )
        ->sort( [ $field => $direction ] )
        ->getPaginator( $perPage );

        ->getPaginator( $perPage, $currentPage, 'commentsPage' );


Laravel's package of Yamop supports native like authentication. You must first extend your User Model with Yamop's Mawelous\YampoLaravel\User

    class User extends Mawelous\YamopLaravel\User
        protected static $_collectionName = 'users';    

In auth\config.php change the driver to yamop.

    'driver' => 'yamop',

Now you can implement it as standard authentication:

    class AuthController extends BaseController {
        public function getLogin()
            return View::make( 'auth.login' );
        public function postLogin()
            if( Auth::attempt( [ 'nickname' => Input::get( 'nickname' ), 'password' => input::get( 'password' ) ] ) )
                return Redirect::intended( 'dashboard' );
            } else {
                return Redirect::to( '/login' )->with( 'login_failed', true );


Any issues or questions please report here


Yamop is free software distributed under the terms of the MIT license