国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

Laravel如何自定義command命令淺析

2024-05-05 00:07:52
字體:
來源:轉載
供稿:網友

前言

用過Laravel的都知道,Laravel通過php artisan make:controller可以生成控制器,同樣的夜可以用命令生成中間介和模型,那怎么自定義生成文件呢?

下面話不多說了,來一起看看詳細的介紹吧

自定義方法如下:

1.創建command類

<?phpnamespace App/Console/Commands;use Illuminate/Console/GeneratorCommand;class ServiceMakeCommand extends GeneratorCommand{ /**  * The console command name.  *  * @var string  */ protected $name = 'make:service'; /**  * The console command description.  *  * @var string  */ protected $description = 'Create a new service class'; /**  * The type of class being generated.  *  * @var string  */ protected $type = 'Services'; /**  * Get the stub file for the generator.  *  * @return string  */ protected function getStub() {  return __DIR__.'/stubs/service.stub'; } /**  * Get the default namespace for the class.  *  * @param string $rootNamespace  * @return string  */ protected function getDefaultNamespace($rootNamespace) {  return $rootNamespace."/Services"; }}

2.在Commands/stubs文件下創建自定義模板文件

<?phpnamespace DummyNamespace;class DummyClass { public function __construct() { }}

創建了一個只有構造函數的類,具體模板可以自己定義

運行測試

php artisan make:service Web/TestService

這個時候Services文件下的Web目錄下會生成TestService文件,Web目錄不存在時會自動創建

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對VeVb武林網的支持。


注:相關教程知識閱讀請移步到PHP教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 岳阳县| 湖南省| 上饶县| 宁南县| 万荣县| 泰兴市| 金湖县| 平乡县| 那坡县| 平乡县| 土默特左旗| 凌源市| 杭州市| 黄浦区| 称多县| 灵宝市| 阳江市| 大姚县| 连州市| 依安县| 宁海县| 安阳县| 息烽县| 青田县| 黔南| 淮阳县| 来宾市| 游戏| 崇仁县| 册亨县| 鸡西市| 商河县| 凭祥市| 苍梧县| 安龙县| 南丹县| 西和县| 龙山县| 平顺县| 晋宁县| 扎鲁特旗|