Skip to content

Instantly share code, notes, and snippets.

@NemanyaM
Forked from vkbansal/artisan.php
Created September 1, 2016 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NemanyaM/82126ba0d44179f73cd63216ddd11fa5 to your computer and use it in GitHub Desktop.
Save NemanyaM/82126ba0d44179f73cd63216ddd11fa5 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