佳木斯湛栽影视文化发展公司

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

Laravel如何自定義command命令淺析

熱門標(biāo)簽:科大訊飛語音識(shí)別系統(tǒng) 電子圍欄 銀行業(yè)務(wù) 阿里云 團(tuán)購網(wǎng)站 Linux服務(wù)器 服務(wù)器配置 Mysql連接數(shù)設(shè)置

前言

用過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é)

以上就是這篇文章的全部內(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)簽:廣元 萍鄉(xiāng) 棗莊 衡水 江蘇 衢州 蚌埠 大理

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Laravel如何自定義command命令淺析》,本文關(guān)鍵詞  ;如發(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)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    泗阳县| 华池县| 龙游县| 宜章县| 建湖县| 呼玛县| 米林县| 许昌市| 阿瓦提县| 洛扎县| 金堂县| 陵川县| 三门峡市| 彭水| 绥棱县| 陵水| 苍山县| 观塘区| 鹤壁市| 尼玛县| 且末县| 称多县| 乌恰县| 台北县| 黔东| 布拖县| 金阳县| 彭阳县| 那曲县| 井陉县| 临漳县| 凯里市| 滨海县| 额济纳旗| 金堂县| 广德县| 阿图什市| 黄山市| 清丰县| 肇庆市| 万源市|