Tying to use artisan migrate commands outside laravel
<?php | |
require_once "vendor/autoload.php"; | |
use Symfony\Component\Console\Application; | |
use Illuminate\Database\Console\Migrations; | |
use Pimple\Container; | |
$container = new Container(); | |
$container['migration-table'] = 'migration'; | |
$container['db-config'] = [ | |
'driver' => 'pgsql', | |
'host' => 'localhost', | |
'database' => 'dummy', | |
'username' => 'postgres', | |
'password' => 'root', | |
'charset' => 'utf8', | |
'prefix' => '', | |
'schema' => 'public' | |
]; | |
$container['filesytem'] = function ($c) { | |
return new \Illuminate\Filesystem\Filesystem; | |
}; | |
$container['connection'] = function ($c) { | |
$manager = new \Illuminate\Database\Capsule\Manager(); | |
$manager->addConnection($c['db-config']); | |
$manager->setAsGlobal(); | |
$manager->bootEloquent(); | |
return $manager->getConnection('default'); | |
}; | |
$container['resolver'] = function ($c) { | |
$r = new \Illuminate\Database\ConnectionResolver(['default' => $c['connection']]); | |
$r->setDefaultConnection('default'); | |
return $r; | |
}; | |
$container['migration-repo'] = function ($c) { | |
return new \Illuminate\Database\Migrations\DatabaseMigrationRepository($c['resolver'], $c['migration-table']); | |
}; | |
$app = new Application("Foo", "1.0"); | |
$app->add(new Migrations\InstallCommand($container['migration-repo'])); | |
$app->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment