Need help with laravel-doctrine?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

123 Stars 60 Forks 250 Commits 12 Opened issues


An ORM for a Framework for Web Artisans

Services available


Need anything else?

Contributors list

Laravel Doctrine

Join the chat at Scrutinizer Code Quality Build Status SensioLabsInsight

This library is succeeded by laravel-doctrine/orm

Though this library is NOT abandoned a more feature-complete and up to date alternative is available at laravel-doctrine/orm. Check it out!

An ORM for a Framework for Web Artisans

Laravel's Eloquent ORM is excellent 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 as a composer package. Doctrine's

instance is accessible through a facade named
as well as via dependency injection.

Metadata is obtained via the annotation driver or a custom config driver that leverages a Laravel-like configuration syntax.


Installation is the usual for Laravel packages.

Insert the following configs in your

"minimum-stability": "dev",
"prefer-stable": true

In the packages section (require):

"atrauzzi/laravel-doctrine": "dev-master"

After that, just run a

composer update

Add the service provider to your Laravel application in

. In the
array add:

If desired, add the following to your

array in the same file:
'EntityManager' => Atrauzzi\LaravelDoctrine\Support\Facades\Doctrine::class,

You need to run this command publish package configuration.

php artisan vendor:publish --provider="Atrauzzi\LaravelDoctrine\ServiceProvider" --tag="config"


You can obtain the

instance for your connection simply by using the

Adapted from Doctrine's documentation:


Sample Entity in Laravel 5:

namespace App\Lib\Domain\Entities;

use Doctrine\ORM\Mapping as ORM; use Atrauzzi\LaravelDoctrine\Trait\Time;


  • @ORM\Entity

  • @ORM\Table(name="Post")

  • / class Post { use Time;


    • @ORM\Id
    • @ORM\GeneratedValue
    • @ORM\Column(type="integer")
    • / private $id; /**
    • @ORM\Column(type="string")
    • / private $title; /**
    • @ORM\Column(type="text")
    • / private $body; public function __construct($input) { $this->setTitle($input['title']); $this->setBody($input['body']); } public function getId() { return $this->id; } public function getTitle() { return $this->title; } public function setTitle($title) { $this->title=$title; } public function setBody($body) { $this->body=$body; } public function getBody() { return $this->body; } }

It is recommended that you read through all of the ORM documentation. Try using Laravel's console to experiment and go through the tutorials.


Doctrine Console

If you need to run ORM commands it is necessary a

file at root project folder having the following implementation:
require DIR.'/bootstrap/autoload.php';

/** @var Application $app */ $app = require_once DIR.'/bootstrap/app.php';

/** @var Illuminate\Contracts\Http\Kernel $kernel */ $kernel = $app->make('Illuminate\Contracts\Console\Kernel'); $kernel->bootstrap();


$entityManager = $app->make('Doctrine\ORM\EntityManager');

return ConsoleRunner::createHelperSet($entityManager);

For validate your schema, you can do:

$ vendor/bin/doctrine orm:validate-schema

Authentication driver

This package allows you to customize the authentication driver using your own user model. In order to use doctrine authentication driver you need to keep in mind the following structure.

  • Having user model representing an authenticatable user into your application
  • Edit
    config file to set authentication model and user provider
  • Edit
    config file to set authentication driver.

Now, let's understand how this driver works.

User model

Your application must has a model implementing

. By default, this package comes with a Doctrine Authentication provider that works with a model using its
as unique valid credentials. The code below shows a valid user model:
namespace App\Models;

use Illuminate\Contracts\Auth\Authenticatable;


  • Class User

  • @entity

  • @table(name="users")

  • / class User implements Authenticatable {


    • @var int

    • @column(type="integer", name="id_user")

    • @generatedValue(strategy="AUTO")

    • @id

    • / protected $id;


    • @var string

    • @column(type="string", unique=true)

    • / protected $email;


    • @var string

    • @column(type="string")

    • / protected $password;


    • @var string

    • @column(type="string")

    • / protected $token;

      public function getEmail() { return $this->email; }

      public function getPassword() { return $this->password; }

 * Get the unique identifier for the user.
 * @return mixed
public function getAuthIdentifier()
    return $this->id;

 * Get the password for the user.
 * @return string
public function getAuthPassword()
    return $this->password;

 * Get the token value for the "remember me" session.
 * @return string
public function getRememberToken()
    return $this->token;

 * Set the token value for the "remember me" session.
 * @param  string $value
 * @return void
public function setRememberToken($value)
    $this->token = $value;

 * Get the column name for the "remember me" token.
 * @return string
public function getRememberTokenName()
    return 'remember_me_token';


It is important to know that laravel needs that our model accomplishes with some rules provided by this interface:

  • getAuthIdentifier()
  • getRememberToken()
  • setRememberToken($value)
  • getRememberTokenName()

Once you have created a valid user model, you are able to specify it in doctrine config file as below:

'auth' => [
    'authenticator' => 'Atrauzzi\LaravelDoctrine\DoctrineAuthenticator',
    'model' => 'App\Models\User',
  • If you want to base your authentication system by
    you can use the default doctrine authenticator.
  • If you need to implement your own doctrine authenticator then set
    key by passing the classname.
  • If you want to use the native laravel auth driver, then set
    key a
    value or just comment it.

Finally, to set doctrine driver as default authentication system you need to set the value as

'driver' => 'doctrine.auth',


The Laravel framework is open-sourced software license under the MIT license

This project is too to ensure maximum compatibility.


I'm interested in hearing feedback and suggestions about this package. Please feel free to submit a ticket at any time.

Visit laravel-doctrine:

laravel-doctrine is made by Alexander Trauzzi with help from all the people in

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.