Laravel 自定命令以及生成文件的例子
2019-10-23 18:05
1856 查看
以创建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 自定命令以及生成文件的例子就是小编分享给大家的全部内容了,希望能给大家一个参考
您可能感兴趣的文章:
相关文章推荐
- Eclipse自动生成文件注释以及使用javadoc命令自动生成API文档
- golang 生成gdb 调试文件 以及gdb命令
- Thrift在windows下的安装以及thrift命令生成java文件
- 关于java poi itext生成pdf文件的例子以及方法
- 获取文件夹下的文件名生成新的文件&DOC命令想从指定的txt中读出文件名,然后在指定文件夹以及子目录下搜索文件,并拷贝到指定目录
- 利用javah生成jni 头文件命令以及问题解决方法
- Laravel 的 make:auth Artisan 命令到底生成了哪些文件?
- CMD文件中用FOR命令读取文本文件内容到变量,以及和PsExec搭配使用的方法和例子
- Thrift在windows下的安装以及thrift命令生成java文件
- ldconfig命令以及/etc/ld.so.cache , /etc/ld.so.conf等文件详细说明
- C语言预处理概述以及文件包含命令
- python(dict字典相关知识以及小例子:生成一个列表,存放100个随机整数,找出出现次数最多的数字)
- Laravel 将数据表中的数据导出,并生成seed文件
- PHP中使用smarty生成静态文件的例子
- Linux中文件的可读,可写,可执行权限的解读以及chmod,chown,chgrp命令的用法
- linux中make命令的简单使用以及Makefile文件的书写
- 命令行下使用javah命令生成.h文件,出现“错误: 无法访问android.app.Activity 找不到android.app.Activity的类文件”的解决方法
- LinuxStudyNote(18)-Linux常用命令(2)-文件处理命令(13)-文件显示(4)-less分页显示文件内容往前翻页以及内容查找
- 【批量生成10万条sql数据库数据+IO流的使用】生成简单sql插入语句大量数据,以及输出流生成文件2017年
- mybatis逆向工程自动生成实体类、接口以及映射Mapper.xml配置文件