• 企业400电话
  • 网络优化推广
  • AI电话机器人
  • 呼叫中心
  • 全 部 栏 目

    网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    Laravel 自定命令以及生成文件的例子
    POST TIME:2021-10-18 04:03

    以创建service层为例子

    1、执行命令

    php artisan make:command ServiceMakeCommand

    2、在app\Console\Commands 下就会多出一个 ServiceMakeCommand.php 文件 ,更改其内容为一下内容 ( 注意:

    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、创建模版

    在 app\Console\Commands\ 下创建stubs文件夹 ,并创建文件service.stub,其内容为

    ?php
    
    namespace DummyNamespace;
    
    class DummyClass
    {
     public function __construct()
     {
     parent::__construct();
     }
    }
    

    4、现在就已经完成了,运行 php artisan list,就可以看到

    执行 php artisan make:service BaseService 就有BaseService.php 文件了

    以上这篇Laravel 自定命令以及生成文件的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

    您可能感兴趣的文章:
    • laravel-admin自动生成模块,及相关基础配置方法
    • laravel批量生成假数据的方法
    • Laravel 自动生成验证的实例讲解:login / logout
    • Laravel自动生成UUID,从建表到使用详解
    上一篇:laravel 创建命令行命令的图文教程
    下一篇:php适配器模式简单应用示例
  • 相关文章
  • 

    关于我们 | 付款方式 | 荣誉资质 | 业务提交 | 代理合作


    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

    X

    截屏,微信识别二维码

    微信号:veteran88

    (点击微信号复制,添加好友)

     打开微信