/orm

A drop-in Doctrine ORM 2 implementation for Laravel 5+

Primary LanguagePHPMIT LicenseMIT

Laravel Doctrine

GitHub release Travis Scrutinizer Packagist Packagist Packagist

This software is STILL IN DEVELOPMENT.

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

Documentation

Begin reading the full documentation here or go to a specific chapter right away.

  1. Installation
  2. Basics
  3. Entities
  4. Meta Data
    1. Annotations
    2. YAML
    3. XML
    4. Config files
    5. StaticPHP
  5. EntityManager
  6. Multiple Connections
  7. Repositories
  8. Console Commands
  9. Configuration
  10. Connections
  11. Meta Data
  12. Caching
  13. Extensions
  14. Authentication
  15. Softdeletes
  16. Timestamps
  17. Table Prefixing
  18. DoctrineExtensions
  19. Writing your own extensions
  20. Configuration Migration
  21. Using the Configuration Migration Command
  22. Writing a template for configurations

Installation

Require this package

"composer require laravel-doctrine/orm"

After adding the package, 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"

Quick start

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.

License

This package is licensed under the MIT license.