The Object Relational Mapper (ORM) for PHP sits on top of a powerful DataBase Abstraction Layer (DBAL). One of its key features is the option to write database queries in a proprietary, object oriented, SQL dialect called Doctrine Query Language (DQL), inspired by Hibernates HQL. This provides developers with a powerful alternative to SQL that maintains flexibility without requiring unnecessary code duplication.
To set up Doctrine, there is a bridge that allows you to perform a matching action with Laravel 5’s existing configuration. In order to install Doctrine2 within your Laravel project, you need to run the following commands step by step:
Step 1: Add the package (delivered by the service provider) to the app/config.php:
composer require laravel-doctrine/orm
Step 2: Configure the alias:
LaravelDoctrine\ORM\DoctrineServiceProvider::class
Step 3: Publish the package configuration:
'EntityManager' => LaravelDoctrine\ORM\Facades\EntityManager::class
Step 4: Doctrine does not require database configuration and uses the current Laravel configuration as:
php artisan vendor:publish --tag="config"
But if you want to override the current Laravel configuration, then you should change the code in Config/doctrine.php (Doctrine config file) as:
'managers' => [ 'default' => [ 'dev' => env('APP_DEBUG'), 'meta' => env('DOCTRINE_METADATA', 'annotations'), 'connection' => env('DB_CONNECTION', 'mysql'), 'namespaces' => [ 'App' ],
And you should be all set!