PHPackages                             opensolutions/doctrine2bridge - 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

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

opensolutions/doctrine2bridge
=============================

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

v2.4.5(12y ago)133.8k2MITPHPPHP &gt;=5.3.0

Since Jan 20Pushed 10y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (2)Versions (7)Used By (0)

Doctrine2Bridge
===============

[](#doctrine2bridge)

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

Laravel's Eloquent ORM is nice for lightweight use, however there's little out there that can beat Doctrine when you need a more full-featured ORM.

This is an integration of Doctrine 2.x to Laravel 4.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/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": "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.

Note that your minimum stability must be `dev` for Doctrine migrations. If the above command complains, ensure you have the following set in your `composer.json` file:

```
"minimum-stability": "dev"

```

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 public and edit the configuration file:

```
./artisan config:publish opensolutions/doctrine2bridge

```

This should get you a fresh copy of the configuration file in the directory `app`:

```
config/packages/vendor/opensolutions/doctrine2bridge

```

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

Usage
-----

[](#usage)

Two facades are provided - one for the Doctrine2 cache and the other for the entity manager. These can be used as follows:

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

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

```

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

[](#more-detailed-usage)

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

```

```

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

```
./vendor/bin/doctrine2 orm:generate-entities app/models/
./vendor/bin/doctrine2 orm:generate-proxies
./vendor/bin/doctrine2 orm:generate-repositories app/models/

```

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

```
./vendor/bin/doctrine2 orm:schema-tool:drop --force
./vendor/bin/doctrine2 orm:schema-tool:create

```

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 [ORM Designer](http://www.orm-designer.com/) to create and manage my XML schema files.

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

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

If, like me, you spend a lot of time typing `D2EM::getRepository( 'Entities\XXX' )`, then add the following to the end of `bootstrap/start.php`:

```
include $app['path.base'] . '/vendor/opensolutions/doctrine2bridge/src/bootstrap/d2r.php';

```

and then you can replace the above with: `D2R( 'XXX' )`. I use *Entities* as my namespace generally so this function is just as follows (which you can easily change to suit yourself):

```
function D2R( $entity, $namespace = 'Entities' )
{
    return D2EM::getRepository( $namespace . '\\' . $entity );
}

```

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).

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

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 ~19 days

Total

6

Last Release

4441d 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 (20 commits)")

---

Tags

laraveldoctrinedoctrine2

### Embed Badge

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

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

###  Alternatives

[laravel-doctrine/orm

An integration library for Laravel and Doctrine ORM

8385.5M96](/packages/laravel-doctrine-orm)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1155.2k](/packages/rcsofttech-audit-trail-bundle)[ocramius/doctrine-batch-utils

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

3331.7M7](/packages/ocramius-doctrine-batch-utils)[laravel-doctrine/migrations

Doctrine Migrations for Laravel

782.8M17](/packages/laravel-doctrine-migrations)

PHPackages © 2026

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