Laravel Command命令行

make:command php artisan make:command Test/Test生成新命令
在app/Console/Kernel.php文件当中注册命令
protected $commands = [
//
TestCommand::class,
];
编辑命令
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = ‘test:test {name} {date?} {default=default} {–op1=}’;
//{name} 必须参数 {date?} 非必须 {default=default}默认参数 {–op1}设置项
/**
* The console command description.
*
* @var string
*/
protected $description = ‘命令描述’;

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$argument = $this->argument();
print_r($argument);
echo $this->option(‘op1’);
$this->info(‘提示信息’);
}
执行命令
php artisan test:test name1 date1 default –op1=option1
//程序调用
Artisan::call(“test:test”, array(‘name’ => ‘test’, ‘date’ => ‘date1’, ‘default’ => ‘def’,’–op1′ => ‘option’));



Tagged , . Bookmark the permalink.

Comments are closed.