Doctrine cli-config.php for Laravel 5
February 24 2015, 2:53am
Doctine requires a custom made cli-config.php
file for Setting up the Commandline Tool with a Laravel 5 application. The CLI tool is necessary when you need to for example clear Doctrine Cache using php vendor/bin/doctrine orm:clear-cache:metadata
.
The following is what you can put in your cli-config.php
:
<?php
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
// replace with file to your own project bootstrap
/** @var Illuminate\Foundation\Application $app */
$app = require_once __DIR__ . '/bootstrap/app.php';
/** @var Illuminate\Contracts\Console\Kernel $kernel */
$kernel = $app->make('Illuminate\Contracts\Console\Kernel');
$kernel->bootstrap();
$app->boot();
// replace with mechanism to retrieve EntityManager in your app
$entityManager = $app[EntityManager::class];
return ConsoleRunner::createHelperSet($entityManager);
Note you will need to have already registered the EntityManager with your app through a service provider. You can use a package like mitchellvanw/laravel-doctrine or opensolutions/doctrine2bridge-l5 to setup Doctrine in Laravel 5.