欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2019年10月23日 10:07:58   作者:侯蜀黍  
今天小編就為大家分享一篇Laravel 自定命令以及生成文件的例子,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

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

1、執(zhí)行命令

php artisan make:command ServiceMakeCommand

2、在app\Console\Commands 下就會(huì)多出一個(gè) 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 自定命令以及生成文件的例子就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論