在用php artisan make:controller
来生成controller
的时候
生成的controller
文件可能不符合我们的要求,
我们有没有办法自定义controller
的内容
app/Console/Commands/makeController.php
<?php
namespace App\Console\Commands;
use Illuminate\Console\GeneratorCommand;
class makeController extends GeneratorCommand
{
/**
* The name and signature of the console command.
*
* @var string
*/
//protected $signature = 'make:controller {name : 名称}';
protected $name = 'make:controller';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
protected $type = 'Controller'; // command type
protected function getStub() {
return __DIR__ . '/stubs/controller.stub';
}
protected function getDefaultNamespace($rootNamespace) {
return $rootNamespace . '\Http\Controllers';
}
}
//https://blog.csdn.net/yageeart/article/details/85875470
以下是controller
模板文件
app/Console/Commands/stubs/controller.stub
<?php
namespace DummyNamespace;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Request;
class DummyClass extends Controller {
public function index() {
echo "<pre>";
print_r(Request::all());
}
}
执行命令php artisan make:controller Test/ApiController
那可生成我们自定义的controller
app/Http/Controllers/Test/ApiController.php
<?php
namespace App\Http\Controllers\Test;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Request;
class ApiController extends Controller {
public function index() {
echo "<pre>";
print_r(Request::all());
}
}
如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术
转载请注明:laravel框架自定义make:controller命令 出自老鄢博客 | 欢迎分享