濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > Laravel如何自定義command命令淺析

Laravel如何自定義command命令淺析

熱門標(biāo)簽:智能電話機(jī)器人排名前十名南京 西區(qū)企業(yè)怎么做地圖標(biāo)注入駐 保定crm外呼系統(tǒng)運(yùn)營(yíng)商 抖音有個(gè)地圖標(biāo)注是什么意思 阿里云400電話申請(qǐng)加工單 七魚外呼系統(tǒng)停用嗎 海南人工外呼系統(tǒng)有效果嗎 地下城堡2圖九地圖標(biāo)注 九江外呼系統(tǒng)

前言

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

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

自定義方法如下:

1.創(chuàng)建command類

?php

namespace 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文件下創(chuàng)建自定義模板文件

?php

namespace DummyNamespace;

class DummyClass 
{
 public function __construct()
 {

 }
}

創(chuàng)建了一個(gè)只有構(gòu)造函數(shù)的類,具體模板可以自己定義

運(yùn)行測(cè)試

php artisan make:service Web/TestService

這個(gè)時(shí)候Services文件下的Web目錄下會(huì)生成TestService文件,Web目錄不存在時(shí)會(huì)自動(dòng)創(chuàng)建

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。

您可能感興趣的文章:
  • Laravel學(xué)習(xí)筆記之Artisan命令生成自定義模板的方法
  • 詳細(xì)Laravel5.5執(zhí)行表遷移命令出現(xiàn)表為空的解決方案
  • laravel通過創(chuàng)建自定義artisan make命令來新建類文件詳解
  • laravel 創(chuàng)建命令行命令的圖文教程

標(biāo)簽:昭通 十堰 甘肅 梅河口 韶關(guān) 遼陽(yáng) 九江 涼山

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Laravel如何自定義command命令淺析》,本文關(guān)鍵詞  Laravel,如何,自定義,command,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Laravel如何自定義command命令淺析》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于Laravel如何自定義command命令淺析的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    清水县| 襄城县| 遂宁市| 宁强县| 扎赉特旗| 孟州市| 鄄城县| 黑水县| 当雄县| 息烽县| 霸州市| 汕头市| 嘉义市| 崇信县| 安徽省| 绥宁县| 印江| 敦化市| 韩城市| 桐柏县| 包头市| 龙口市| 五家渠市| 吴忠市| 建阳市| 孝感市| 华坪县| 房产| 临猗县| 孙吴县| 中山市| 塘沽区| 新闻| 东明县| 天峻县| 高密市| 雅江县| 衡阳市| 东方市| 曲松县| 武义县|