1 生成命令
php artisan make:command AppMakeCommand
该命令会在 app/Console/Commands 目录下创建一个新的命令类
在 Commands 目录下 差创建 stubs 目录 放入模板文件 controller.plain.stub
controller.plain.stub 内容 :
<?php
namespace DummyNamespace;
DummyUseNamespace
class DummyClass extends DummyInheritClassController
{
//
}
2 更改命令文件
AppMakeCommand 文件替换 :
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
class AppMakeCommand extends Command
{
protected $files;
protected $type = 'AppControllers';
/**
* The name and signature of the console command. 控制台命令的名称和签名
*
* @var string
*/
protected $signature = 'make:appControllers {name} {--inherit=}';
/**
* The console command description. 控制台命令描述
*
* @var string
*/
protected $description = 'Create a new appControllers class';
/**
* Create a new command instance. 创建一个新的命令实例
*
* @return void
*/
public function __construct(Filesystem $files)
{
parent::__construct();
$this->files = $files;
}
/**
* Execute the console command. 执行控制台命令
* @return bool
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function handle()
{
$name = $this->qualifyClass($this->getNameInput());
$path = $this->getPath($name);
if ((! $this->hasOption('force') ||
! $this->option('force')) &&
$this->alreadyExists($this->getNameInput())) {
$this->error($this->type.' already exists!');
return false;
}
// Next,