Skip to content

Instantly share code, notes, and snippets.

@hkan
Last active December 30, 2015 15:39
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 hkan/7849565 to your computer and use it in GitHub Desktop.
Save hkan/7849565 to your computer and use it in GitHub Desktop.
Laravel Artisan Auto Migration Command
<?php
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class InstallCommand extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'migrate:auto';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Automatically does migrations and seedings.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
if ( ! Schema::hasTable(Config::get('database.migrations')))
$this->call('migrate:install');
// is fresh install
if ($this->option('fresh'))
{
$this->call('migrate:reset');
}
if (Config::get('session.driver') == 'database')
$this->call('session:table');
$this->call('migrate');
// is seed enabled
if ($this->option('seed'))
{
$this->call('db:seed');
}
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array();
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array(
array('fresh', null, InputOption::VALUE_OPTIONAL, 'Fresh installation', false),
array('seed', null, InputOption::VALUE_OPTIONAL, 'Seed tables', true)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment