Home

Awesome

Laravel PHPMongo Adapter

Laravel Adapter for PHPMongo ORM

Total Downloads

Installation

Add composer dependency:

composer require phpmongokit/laravel-mongo-odm

Register provider in ./config/app.php:

<?php

return [
    'providers' => [
        PHPMongoKit\ODM\Adapter\Laravel\MongoDbServiceProvider::class,
    ],
];

Add configuration of your connections to ./config/mongodb.php:

<?php

return [
    'connections' => [
        'connect1' => [
            'dsn' => 'mongodb://mongodb',
        ],
    ],
];

Usage

Get connection pool from service container:

<?php

use Psr\Container\ContainerInterface;
use Sokil\Mongo\ClientPool;

Route::get('/', function (ContainerInterface $container) {
    /** @var ClientPool $clientPool */
    $clientPool = $container->get(ClientPool::class);
    $connection = $clientPool->get('connect1'); // Instance of Sokil\Mongo\Client
});