最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Laravel如何自定義command命令淺析

 更新時(shí)間:2019年03月23日 08:43:33   作者:緣來是你ylh  
這篇文章主要給大家介紹了關(guān)于Laravel如何自定義command命令的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用Laravel具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧

前言

用過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)行測試

php artisan make:service Web/TestService

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

總結(jié)

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

相關(guān)文章

最新評論

呼伦贝尔市| 行唐县| 岳池县| 建始县| 舟曲县| 马关县| 陆良县| 罗源县| 赤水市| 民勤县| 平湖市| 桑植县| 甘南县| 苏尼特右旗| 平果县| 渭源县| 奉化市| 滨海县| 昂仁县| 邹平县| 天柱县| 江都市| 酉阳| 南川市| 延津县| 永兴县| 昌图县| 白城市| 兴仁县| 许昌市| 尼勒克县| 海淀区| 呼玛县| 九龙坡区| 高要市| 长泰县| 会理县| 洛浦县| 收藏| 上蔡县| 郸城县|