PHPackages                             opensolutions/doctrine2bridge-l5 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. opensolutions/doctrine2bridge-l5

ActiveLibrary[Database &amp; ORM](/categories/database)

opensolutions/doctrine2bridge-l5
================================

Adds the the power of Doctrine2 to Laravel 5 (with support for SQL logging and authentication)

v2.4.3(10y ago)92662MITPHPPHP &gt;=5.5.0

Since Feb 7Pushed 10y ago3 watchersCompare

[ Source](https://github.com/opensolutions/doctrine2bridge-l5)[ Packagist](https://packagist.org/packages/opensolutions/doctrine2bridge-l5)[ Docs](https://github.com/opensolutions/doctrine2bridge-l5)[ RSS](/packages/opensolutions-doctrine2bridge-l5/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (5)Used By (0)

NB: You are advised to use this project from here on in:
======================================================================================

[](#nb-you-are-advised-to-use-this-project-from-here-on-in-httplaraveldoctrineorg)

Doctrine2Bridge for Laravel 5
=============================

[](#doctrine2bridge-for-laravel-5)

Adds the power of Doctrine2 to Laraval 5 (including authentication and SQL query logging support).

For Laravel4, see [opensolutions/doctrine2bridge](https://github.com/opensolutions/doctrine2bridge)

Laravel's Eloquent ORM is nice for rapid development and the active model pattern. However there's little out there that can beat Doctrine2 when you need a more full-featured ORM.

This is an integration of Doctrine 2.x to Laravel 5.x as a composer package. Doctrine's EntityManager instance is accessible through a facade named `D2EM` and the cache is directly available via `D2Cache`.

Metadata is currently obtained via the [XML driver](http://docs.doctrine-project.org/en/latest/reference/xml-mapping.html). It should be easy to add additional drivers to this.

Authentication support is also included via a `Auth/Doctrine2UserProvider` class. Documentation on integrating this with Laravel's own authentication system [can be found here](https://github.com/opensolutions/doctrine2bridge/wiki/Auth).

Installation
------------

[](#installation)

Installation is the usual for Laravel packages. You can find a detailed worked version of [how to install and test in the wiki](https://github.com/opensolutions/doctrine2bridge-l5/wiki/Install-from-Scratch).

Insert the following in the packages (`require`) section of your composer.json file and run an update (`composer update`):

```
"opensolutions/doctrine2bridge-l5": "2.4.*",

```

Generally speaking, we'll try and match our minor versions (2.4.x) with Doctrine's but you should always use the latest `x` version of this.

Add the service providers to your Laravel application in `app/config/app.php`. In the `'providers'` array add:

```
'Doctrine2Bridge\Doctrine2CacheBridgeServiceProvider',
'Doctrine2Bridge\Doctrine2BridgeServiceProvider',

```

You'll need to publish and edit the configuration files:

```
./artisan vendor:publish --provider "Doctrine2Bridge\Doctrine2CacheBridgeServiceProvider"
./artisan vendor:publish --provider "Doctrine2Bridge\Doctrine2BridgeServiceProvider"

```

This should get you a fresh copy of the configuration files (`d2bcache.php` and `db2doctrine.php`) in the configs directory.

Now, edit these as well as setting Laravel5's own `cache.php` and `database.php` appropriately.

The default directory for Doctrine2's xml schema is `database/xml`. This can be configured in `config/d2bdoctrine.php`.

Documentation on integrating this with Laravel's own authentication system [can be found here](https://github.com/opensolutions/doctrine2bridge-l5/wiki/Auth).

Usage
-----

[](#usage)

Four bindings are created which can be injected via Laravel's IoC in the standard manner:

- `Doctrine\ORM\EntityManagerInterface` (which is an instance of Doctrine\\ORM\\EntityManager)
- `Doctrine\Common\Cache\Cache` (which is an instance of the appropriate cache provider)
- `Doctrine\ORM\Mapping\ClassMetadataFactory` (used in this package by the console generator commands)
- `Doctrine2Bridge\Support\Repository` (used by the `D2R` facade, see below)

Three facades are provided - for the Doctrine2 cache, the entity manager and a convenience repository generator. These can be used as follows:

```
D2Cache::save( $key, $value );
D2Cache::fetch( $key );

D2EM::persist( $object );
D2EM::flush();
$users = D2EM::getRepository( 'Entities\User' )->findAll();

```

Typically we'd create and use a repository as follows:

```
$sample = D2EM::getRepository( '\Entities\SampleEntity' )->find(5);

```

Assuming `d2bdoctrine.namespaces.models => 'Entities'`, then we can use the `D2R` facade in any of the following ways to achieve the same result:

```
$sample = D2R::r( 'SampleEntity' )->find(5);
$sample = D2R::r( 'Entities\SampleEntity' )->find(5);
$sample = D2R::r( 'SampleEntity', 'Entities' )->find(5);

```

More Detailed Usage
-------------------

[](#more-detailed-usage)

The configuration file by default expects to find XML schema definitions under `database/xml`. Let's say for example we have a single schema file called `database/xml/Entities.SampleEntity.dcm.xml` containing:

```

```

Assuming you've configured your database connection parameters in the config file and you're positioned in the base directory of your project, we can create the entities, proxies and repositories with:

```
./artisan d2b:generate:entities
./artisan d2b:generate:proxies
./artisan d2b:generate:repositories

```

There is also a handy shortcut for this:

```
./artisan d2b:generate:all

```

Read the output of these commands as they may need to be run twice.

We also bundle a full Doctrine2 CLI utilty so the above could also be done via:

```
./vendor/bin/d2b-doctrine2 orm:generate-entities database/
./vendor/bin/d2b-doctrine2 orm:generate-proxies
./vendor/bin/d2b-doctrine2 orm:generate-repositories database/

```

You can also (drop) and create the database with:

```
./artisan d2b:schema:drop --commit
./artisan d2b:schema:create --commit

```

And you can update and validate via:

```
./artisan d2b:schema:update --commit
./artisan d2b:schema:validate

```

Now you can add some data to the database:

```
$se = new Entities\SampleEntity;
$se->setName( rand( 0, 100 ) );
D2EM::persist( $se );
D2EM::flush();

```

And query it:

```
echo count( D2EM::getRepository( 'Entities\SampleEntity' )->findAll() );

```

I use the excellent [Skipper](http://www.skipper18.com/) to create and manage my XML schema files.

Convenience Function for Repositories
-------------------------------------

[](#convenience-function-for-repositories)

SQL Query Logging
-----------------

[](#sql-query-logging)

This package includes an implementation of `Doctrine\DBAL\Logging\SQLLlogger` which times the queries and calls the Laravel [Log](http://laravel.com/docs/errors#logging) facade to log the query execution times and the SQL queries.

This logger can be enabled in the configuration file.

\## License

Like the Laravel framework itself, this project is open-sourced under the [MIT license](http://opensource.org/licenses/MIT).

Inspiration
-----------

[](#inspiration)

Based on my original package [opensolutions/doctrine2bridge](https://github.com/opensolutions/doctrine2bridge) for Laravel4. Some additional inspiration when porting to Laravel5 from [mitchellvanw/laravel-doctrine](https://github.com/mitchellvanw/laravel-doctrine).

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~53 days

Total

4

Last Release

3959d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/804649?v=4)[Barry O'Donovan](/maintainers/barryo)[@barryo](https://github.com/barryo)

---

Top Contributors

[![barryo](https://avatars.githubusercontent.com/u/804649?v=4)](https://github.com/barryo "barryo (17 commits)")

---

Tags

laraveldoctrine2

### Embed Badge

![Health badge](/badges/opensolutions-doctrine2bridge-l5/health.svg)

```
[![Health](https://phpackages.com/badges/opensolutions-doctrine2bridge-l5/health.svg)](https://phpackages.com/packages/opensolutions-doctrine2bridge-l5)
```

###  Alternatives

[laravel-doctrine/orm

An integration library for Laravel and Doctrine ORM

8425.3M87](/packages/laravel-doctrine-orm)[ocramius/doctrine-batch-utils

A set of utilities to operate with Doctrine ORM's batch processing functionality

3331.6M6](/packages/ocramius-doctrine-batch-utils)[webonaute/doctrine-fixtures-generator-bundle

Generate Fixture from your existing data in your database. You can specify the Entity name and the IDs you want to import in your fixture.

67184.1k](/packages/webonaute-doctrine-fixtures-generator-bundle)[laravel-doctrine/fluent

A fluent PHP mapping driver for Doctrine2.

43430.3k13](/packages/laravel-doctrine-fluent)[opensolutions/doctrine2bridge

Adds the the power of Doctrine2 to Laravel 4 (with support for SQL logging and authentication)

133.7k](/packages/opensolutions-doctrine2bridge)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
