Skip to content

Instantly share code, notes, and snippets.

@pragmaton
Forked from vkbansal/artisan.php
Created October 12, 2017 11:47
Show Gist options
  • Save pragmaton/1e2c5b1931522520515a41ddb1a23ee9 to your computer and use it in GitHub Desktop.
Save pragmaton/1e2c5b1931522520515a41ddb1a23ee9 to your computer and use it in GitHub Desktop.
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