Giter Club home page Giter Club logo

laravel-doctrine's Introduction

Doctrine 2 for Laravel

Latest Stable Version License Total Downloads

A Doctrine 2 implementation that melts with Laravel 4.

Documentation

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

  1. Installation
  2. How It Works
  3. Basics
  4. Entity Manager
  5. Timestamps
  6. Soft Deleting
  7. Authentication
  8. Schemas
  9. Doctrine Configuration
  10. Metadata Configuration
  11. Annotation Reader
  12. Metadata
  13. MIT License

Caveats

At the moment Doctrine\ORM version 2.5 is still in beta. As a result the composer install may require you to change the minimum-stability in your composer.json to dev.

If you don't want to affect the stability of the rest of the packages, you can add the following property in your composer.json:

"prefer-stable": true

Installation

Begin by installing the package through Composer. Edit your project's composer.json to require mitchellvanw/laravel-doctrine.

This package is still in it's early stages, but fully functional. Is it possible that the API might change slightly, no drastic changes.

"require": {
    "mitchellvanw/laravel-doctrine": "0.5.*"
}

Next use Composer to update your project from the the Terminal:

php composer.phar update

Once the package has been installed you'll need to add the service provider. Open your app/config/app.php configuration file, and add a new item to the providers array.

'Mitch\LaravelDoctrine\LaravelDoctrineServiceProvider'

After This you'll need to add the facade. Open your app/config/app.php configuration file, and add a new item to the aliases array.

'EntityManager' => 'Mitch\LaravelDoctrine\EntityManagerFacade'

It's recommended to publish the package configuration.

php artisan config:publish mitchellvanw/laravel-doctrine --path=vendor/mitchellvanw/laravel-doctrine/config

2 Minutes

This package uses the Laravel database configuration and thus it works right out of the box. With the Entity Manager facade (or service locator) you can interact with repositories. It might be wise to check out the Doctrine 2 docs to know how it works. The little example below shows how to use the EntityManager in it simplest form.

<?php

$user = new User;
$user->setName('Mitchell');

EntityManager::persist($user);
EntityManager::flush();

The User used in the example above looks like this.

<?php

use Doctrine\ORM\Mapping AS ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="users")
 */
class User
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string")
     */
    private $name;

    public function getId()
    {
        return $this->id;
    }

    public function getName()
    {
        return $this->name;
    }

    public function setName($name)
    {
        $this->name = $name;
    }
}

If you've only used Eloquent and its models this might look bloated or frightening, but it's actually very simple. Let me break the class down.

<?php

use Doctrine\ORM\Mapping AS ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="users")
 */
class User
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string")
     */
    private $name;
}

The only thing that's actually important in this entity are the properties. This shows you which data the entity holds.

With Doctrine 2 you can't interact with database by using the entity User. You'll have to use Entity Manager and repositories. This does create less overhead since your entities aren't extending the whole Eloquent model class. Which can dramatically slow down your application a lot if you're working with thousands or millions of records.

License

This package is licensed under the MIT license.

laravel-doctrine's People

Contributors

baileylo avatar bangipul avatar cosmicist avatar glennjacobs avatar jeremyworboys avatar kirkbushell avatar leonardoalifraco avatar mitchellvanw avatar psampaz avatar sephvelut avatar soyuka avatar stephenfrank avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.