Installation and configuration procedures for laravel and doctrine The following packages that will be installed:
- laravel 5.8
- laravel-doctrine orm 1.4
- laravel-doctrine acl 1.0
- laravel-doctrine migrations 1.1
- laravel-doctrine extensions 1.0
- laravel-doctrine extensions gedmo 2.4
composer create-project --prefer-dist laravel/laravel <PROJECT_DIR_NAME> "5.8.*"
cd <PROJECT_DIR_NAME>
composer update
composer dump-autoload
After the installation, check for .env file. If not yet created, copy the .env.example
file to .env
then generate an application key using the php artisan key:generate
command
composer require "laravel-doctrine/orm:1.4.*"
Open the config/app.php file and add the Doctrine Service Provider for autoloading:
'providers' => [
...
/*
* Doctrine Service Providers...
*/
LaravelDoctrine\ORM\DoctrineServiceProvider::class,
...
]
In the same file config/app.php, set the class aliases for EntityManager, Registry, and Doctrine
copy the code below and append it just below the Service Providers section.
'aliases' => [
...
/*
* Doctrine Class Aliases...
*/
'EntityManager' => LaravelDoctrine\ORM\Facades\EntityManager::class,
'Registry' => LaravelDoctrine\ORM\Facades\Registry::class,
'Doctrine' => LaravelDoctrine\ORM\Facades\Doctrine::class,
...
],
Publish the doctrine and debug config file, use the command below:
- This will create a file doctrine.php file in the config directory
php artisan vendor:publish --tag="config"
Optionally, the base_path in config/doctrine.php can be updated for the location of Entity files
'managers' => [
'default' => [
...
'paths' => [
base_path('app/Database/Entities')
],
...
]
],
composer require "laravel-doctrine/migrations:1.1.*"
Open the config/app.php file and register the Doctrine Migration Service Provider by adding this
LaravelDoctrine\Migrations\MigrationsServiceProvider::class,
line of code as see in the code below:
'providers' => [
...
/*
* Doctrine Service Providers...
*/
LaravelDoctrine\ORM\DoctrineServiceProvider::class,
LaravelDoctrine\Migrations\MigrationsServiceProvider::class,
...
]
Publish the doctrine migration config file, use the command below:
- This will create a file migrations.php file in the config directory
php artisan vendor:publish --tag="config"
composer require "laravel-doctrine/extensions:1.0.*"
composer require "gedmo/doctrine-extensions:^2.4"
Open the config/app.php file and register the Gedmo Doctrine Extension Service Provider by adding this
LaravelDoctrine\Extensions\GedmoExtensionsServiceProvider::class,
line of code as see in the code below:
'providers' => [
...
/*
* Doctrine Service Providers...
*/
LaravelDoctrine\ORM\DoctrineServiceProvider::class,
LaravelDoctrine\Migrations\MigrationsServiceProvider::class,
LaravelDoctrine\Extensions\GedmoExtensionsServiceProvider::class,
...
]
Open the config/doctrine.php file and uncomment the timestamp extension:
'extensions' => [
...
LaravelDoctrine\Extensions\Timestamps\TimestampableExtension::class,
...
],
- Install when there's a need for role base functinality
Laravel Doctrine ACL offers:
- User can belong to Organisation(s)
- User can have Roles
- User and Roles can have Permissions
- Seamless integration with Laravel's Authorization system
composer require "laravel-doctrine/acl:^1.0"
Open the config/app.php file and register the Doctrine ACL Service Provider by adding this
LaravelDoctrine\ACL\AclServiceProvider::class,
line of code as see in the code below:
'providers' => [
...
/*
* Doctrine Service Providers...
*/
LaravelDoctrine\ORM\DoctrineServiceProvider::class,
LaravelDoctrine\Migrations\MigrationsServiceProvider::class,
LaravelDoctrine\Extensions\GedmoExtensionsServiceProvider::class,
LaravelDoctrine\ACL\AclServiceProvider::class,
...
]
Publish the doctrine acl config file, use the command below:
After publishing, you should check the class name the
acl.roles.entity
config to your class,
by default this is set toApp\Role
.
php artisan vendor:publish --tag="config"
The following configurations will allow us to run laravel without the using the artisan command php artisan serve
.
We can instead use localhost:<PORT_NUMBER>
in the browsers' address bar
Locate and open the file httpd.conf file then add a new port to listen
Listen <PORT_NUMBER>
Locate and open the file httpd-vhosts.conf then add a new vhost entry
<VirtualHost *:<PORT_NUMBER>>
ServerName <PROJECT_NAME>.localhost
DocumentRoot "<INSTALL_LOCATION>/<PROJECT_DIR_NAME>/public/"
<Directory "<INSTALL_LOCATION>/<PROJECT_DIR_NAME>">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>