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

主頁 > 知識庫 > Laravel 自定命令以及生成文件的例子

Laravel 自定命令以及生成文件的例子

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

以創(chuàng)建service層為例子

1、執(zhí)行命令

php artisan make:command ServiceMakeCommand

2、在app\Console\Commands 下就會多出一個 ServiceMakeCommand.php 文件 ,更改其內(nèi)容為一下內(nèi)容 ( 注意:

1、承了GeneratorCommand類,

2、protected $signature = 'make:service {name}'; 中{name}必須要有

?php

namespace App\Console\Commands;

use Illuminate\Console\GeneratorCommand;

class ServiceMakeCommand extends GeneratorCommand
{
 /**
 * The name and signature of the console command.
 *
 * @var string
 */
 protected $signature = 'make:service {name}';

 /**
 * The console command description.
 *
 * @var string
 */
 protected $description = 'Create a service';
 /**
 * 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';
 }
}

3、創(chuàng)建模版

在 app\Console\Commands\ 下創(chuàng)建stubs文件夾 ,并創(chuàng)建文件service.stub,其內(nèi)容為

?php

namespace DummyNamespace;

class DummyClass
{
 public function __construct()
 {
 parent::__construct();
 }
}

4、現(xiàn)在就已經(jīng)完成了,運(yùn)行 php artisan list,就可以看到

執(zhí)行 php artisan make:service BaseService 就有BaseService.php 文件了

以上這篇Laravel 自定命令以及生成文件的例子就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • laravel-admin自動生成模塊,及相關(guān)基礎(chǔ)配置方法
  • laravel批量生成假數(shù)據(jù)的方法
  • Laravel 自動生成驗(yàn)證的實(shí)例講解:login / logout
  • Laravel自動生成UUID,從建表到使用詳解

標(biāo)簽:棗莊 廣元 衡水 江蘇 萍鄉(xiāng) 大理 衢州 蚌埠

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Laravel 自定命令以及生成文件的例子》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    化州市| 安图县| 渑池县| 边坝县| 西昌市| 三台县| 屯昌县| 金湖县| 南木林县| 佛冈县| 临颍县| 库车县| 岳池县| 福鼎市| 皋兰县| 海宁市| 莲花县| 昌都县| 合阳县| 龙井市| 双流县| 容城县| 安福县| 岱山县| 永安市| 潢川县| 申扎县| 西宁市| 会东县| 黔西| 永仁县| 富民县| 汝南县| 磐安县| 措勤县| 龙岩市| 额尔古纳市| 竹山县| 蒲江县| 武山县| 武平县|