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:
1 |
composer require laravel-doctrine/orm |
Step 2: Configure the alias:
1 |
LaravelDoctrine\ORM\DoctrineServiceProvider::class |
Step 3: Publish the package configuration:
1 |
'EntityManager' => LaravelDoctrine\ORM\Facades\EntityManager::class |
Step 4: Doctrine does not require database configuration and uses the current Laravel configuration as:
1 |
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:
1 2 3 4 5 6 7 8 |
'managers' => [ 'default' => [ 'dev' => env('APP_DEBUG'), 'meta' => env('DOCTRINE_METADATA', 'annotations'), 'connection' => env('DB_CONNECTION', 'mysql'), 'namespaces' => [ 'App' ], |
And you should be all set!
Comments are closed.