Created
June 17, 2014 02:28
-
-
Save ayonliu/9a1ddeddd2512ba0eaaa to your computer and use it in GitHub Desktop.
Create command in Laravel
This file contains hidden or 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 | |
/* | |
/ app/start/artisan.php | |
|-------------------------------------------------------------------------- | |
| Register The Artisan Commands | |
|-------------------------------------------------------------------------- | |
| | |
| Each available Artisan command must be registered with the console so | |
| that it is available to be called. We'll register every command so | |
| the console gets access to each of the command object instances. | |
| | |
*/ | |
Artisan::add(new NewCommand()); |
This file contains hidden or 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 | |
// app/commands/NewCommand.php | |
use Illuminate\Console\Command; | |
use Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Console\Input\InputArgument; | |
class NewCommand extends Command { | |
/** | |
* The console command name. | |
* | |
* @var string | |
*/ | |
protected $name = 'NewCommand'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'The NewCommand Command description.'; | |
/** | |
* Create a new command instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function fire() | |
{ | |
// do your command job here. | |
echo 'this is new command'; | |
} | |
/** | |
* Get the console command arguments. | |
* | |
* @return array | |
*/ | |
protected function getArguments() | |
{ | |
return array( | |
// comment this if there is no arguments | |
//array('example', InputArgument::REQUIRED, 'An example argument.'), | |
); | |
} | |
/** | |
* Get the console command options. | |
* | |
* @return array | |
*/ | |
protected function getOptions() | |
{ | |
return array( | |
// comment this if there is no options | |
//array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null), | |
); | |
} | |
} |
This file contains hidden or 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 artisan command:make Newcommand | |
# after execute this, NewCommand.php will be generated under app/commands/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment