Skip to content

Instantly share code, notes, and snippets.

@mcfdn
Created August 15, 2016 16:37
Show Gist options
  • Save mcfdn/f547c93e6a83e5392e4916d930656023 to your computer and use it in GitHub Desktop.
Save mcfdn/f547c93e6a83e5392e4916d930656023 to your computer and use it in GitHub Desktop.

Revisions

  1. mcfdn created this gist Aug 15, 2016.
    40 changes: 40 additions & 0 deletions EntityManagerServiceProvider.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    <?php

    namespace App\Providers;

    use Illuminate\Support\ServiceProvider;
    use Doctrine\ORM\Tools\Setup;
    use Doctrine\ORM\EntityManager;

    class EntityManagerServiceProvider extends ServiceProvider
    {
    /**
    * Bootstrap any application services.
    *
    * @return void
    */
    public function boot()
    {
    //
    }

    /**
    * Register any application services.
    *
    * @return void
    */
    public function register()
    {
    $this->app->singleton('Doctrine\ORM\EntityManager', function ($app) {

    $paths = [app_path('models')];
    $isDevMode = config('app.debug');

    // the connection configuration
    $dbParams = config('database.doctrine');

    $config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
    return EntityManager::create($dbParams, $config);
    });
    }
    }