Skip to content

Instantly share code, notes, and snippets.

@mstaack
Created April 2, 2020 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mstaack/3cf6c874c53979ec6cb26a592df13d7d to your computer and use it in GitHub Desktop.
Save mstaack/3cf6c874c53979ec6cb26a592df13d7d to your computer and use it in GitHub Desktop.
<?php
namespace App\Providers;
use Jenssegers\Mongodb\Connection;
use Jenssegers\Mongodb\Queue\MongoConnector;
class MongodbServiceProvider extends \Jenssegers\Mongodb\MongodbServiceProvider
{
/**
* Register the service provider.
*/
public function register()
{
// Add database driver.
$this->app->resolving('db', function ($db) {
$db->extend('mongodb', function ($config, $name) {
$config['name'] = $name;
$connection = new Connection($config);
// show queries in clockwork
if ($this->app->environment('local')) {
$connection->enableQueryLog();
}
return $connection;
});
});
// Add connector for queue support.
$this->app->resolving('queue', function ($queue) {
$queue->addConnector('mongodb', function () {
return new MongoConnector($this->app['db']);
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment