1.执行命令 php artisan make:command 命令的名字,eg:
php artisan make:command ESinit
2.会在 app\Console\Commands\目录下创建 ESinit.php
class ESinit extends Command
{
/**
* The name and signature of the console command.
* 这是命令的名字
* @var string
*/
//protected $signature = 'command:name';
protected $signature = 'es:init';
/**
* The console command description.
* 命令的描述
* @var string
*/
//protected $description = 'Command description';
protected $description = 'init laravel es for post';
/**
* Create a new command instance.
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* 在这里写实际要做的事情
* Execute the console command.
* @return mixed
*/
public function handle()
{
//todo
}
}
3.在 app\Console\Kernel.php 里
protected $commands = [
\App\Console\Commands\ESinit::class
];
PS:注意,这里一定要从app开始写起,否则无效