Skip to content

Instantly share code, notes, and snippets.

@ayonliu
Created June 17, 2014 02:28
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 ayonliu/9a1ddeddd2512ba0eaaa to your computer and use it in GitHub Desktop.
Save ayonliu/9a1ddeddd2512ba0eaaa to your computer and use it in GitHub Desktop.
Create command in Laravel
<?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());
<?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),
);
}
}
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