It is working software but breaking changes may occur with no prior warning. Do not use this in production!
For more information or to get started contributing visit us on Slack
A drop-in Doctrine ORM 2 implementation for Laravel 5+
- Easy configuration
- Pagination
- Preconfigured metadata, connections and caching
- Extendable: extend or add your own drivers for metadata, connections or cache
- Change metadata, connection or cache settings easy with a resolved hook
- Annotations, yaml, xml, config and static php meta data mappings
- Multiple entity managers and connections
- Laravel naming strategy
- Simple authentication implementation
- Password reminders implementation
- Doctrine console commands
- DoctrineExtensions supported
- Timestamps, Softdeletes and TablePrefix listeners
Begin reading the full documentation here or go to a specific chapter right away.
- Installation
- Basics
- Entities
- Meta Data
- EntityManager
- Multiple Connections
- Repositories
- Console Commands
- Configuration
- Connections
- Meta Data
- Caching
- Extensions
- Authentication
- Softdeletes
- Timestamps
- Table Prefixing
- DoctrineExtensions
- Writing your own extensions
- Configuration Migration
- Using the Configuration Migration Command
- Writing a template for configurations
Require this package in your composer.json
and run composer update
.
"laravel-doctrine/orm": "@dev"
After updating composer, add the ServiceProvider to the providers array in config/app.php
'LaravelDoctrine\ORM\DoctrineServiceProvider',
Optionally you can register the EntityManager facade:
'EntityManager' => 'LaravelDoctrine\ORM\Facades\EntityManager'
To publish the config use:
php artisan vendor:publish --tag="config"
Out of the box this package uses the default Laravel connection which is provided in config/database.php
, which means that you are ready to start fetching and persisting.
<?php
$article = new Article;
$article->setTitle('Laravel Doctrine Quick start');
EntityManager::persist($article);
EntityManager::flush();
Unlike Eloquent, Doctrine is not an Active Record pattern, but a Data Mapper pattern. Every Active Record model extends a base class (with all the database logic), which has a lot of overhead and dramatically slows down your application with thousands or millions of records.
Doctrine entities don't extend any class. The domain/business logic is completely separated from the persistence logic.
This means we have to tell Doctrine how it should map the columns from the database to our Entity class. In this example we are using annotations. Other possiblities are yaml, xml or php array's.
The Article
entity used in the example above looks like this.
<?php
use Doctrine\ORM\Mapping AS ORM;
/**
* @ORM\Entity
* @ORM\Table(name="articles")
*/
class Article
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
protected $id;
/**
* @ORM\Column(type="string")
*/
protected $title;
public function getId()
{
return $this->id;
}
public function getTitle()
{
return $this->title;
}
public function setTitle($title)
{
$this->title = $title;
}
}
To quickly create the articles
table inside your database, run: php artisan doctrine:schema:update
Continue reading the full documentation.
This package is licensed under the MIT license.