Last active
August 29, 2015 14:16
-
-
Save maderaka/4f13f7a9a33615adef9a to your computer and use it in GitHub Desktop.
Laravel 5: Creating migrations for specific package with custom artisan command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace App\Console\Commands; | |
use Illuminate\Console\Command; | |
use Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Console\Input\InputArgument; | |
use Illuminate\Container\Container; | |
class KpMigrationMake extends Command { | |
/** | |
* @var string | |
*/ | |
protected $app; | |
/** | |
* The console command name. | |
* | |
* @var string | |
*/ | |
protected $name = 'kp:migration:make'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Creating migrations for specific package with custom artisan command'; | |
/** | |
* Create a new command instance. | |
* | |
* @return void | |
*/ | |
public function __construct(Container $app) | |
{ | |
parent::__construct(); | |
$this->app = $app; | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function fire() | |
{ | |
$migrator = $this->app->make('migration.creator'); | |
$path = __DIR__ .'/../../../vendor/kp/'; | |
$result = $migrator->create( | |
$this->argument('name'), | |
"{$path}{$this->argument('package')}/migrations", | |
$this->option('table'), | |
$this->option('create') | |
); | |
$this->info("Create migrations : {$result}"); | |
} | |
/** | |
* Get the console command arguments. | |
* | |
* @return array | |
*/ | |
protected function getArguments() | |
{ | |
return [ | |
['name', InputArgument::REQUIRED, 'name migration class'], | |
['package', InputArgument::REQUIRED, 'package name'] | |
]; | |
} | |
/** | |
* Get the console command options. | |
* | |
* @return array | |
*/ | |
protected function getOptions() | |
{ | |
return [ | |
['table', null, InputOption::VALUE_OPTIONAL, 'table name', null], | |
['create', null, InputOption::VALUE_OPTIONAL, 'create mode', false] | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment