phpmongokit/laravel-mongo-odm

PHPMongo Laravel Adapter

0.0.1 2018-02-05 00:13 UTC

This package is auto-updated.

Last update: 2021-04-27 18:38:02 UTC


README

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
});