感触life

用Laravel-modules模块化开发

总流程:1.composer安装laravel-modules插件–>2.命令创建模块–>3.发布模块到github–>4.命令安装模块

前提准备:laravel环境与composer环境

1.跟着官方教程走:https://nwidart.com/laravel-modules/v6/installation-and-setup,建议 安装 对应的laravel版本,如下

composer require nwidart/laravel-modules v4

2. 命令创建模块 , 会在 Modules 目录下创建出一个类似APP的目录来

php artisan module:make Blog

3. 发布模块到github ,这里其实是Modules下的模块创建一个仓库,需要发布版本,在github上面点tags->Releases->Draft a new release,填写版本号等信息即可( 不用官方的发布包到packagist.org,因为composer安装太慢了 )

4.命令安装模块 , 可以先看看安装的原理文件,路径:laravel\vendor\nwidart\laravel-modules\src\Commands\InstallCommand.php ,最终模块会被安装到laravel/modules下

php artisan module:install --type=git地址 -- 模块名 版本

tips:仓库不一定是github,注意安装模块那,模块名面前有空格

这个算是文档中文翻译:https://www.jianshu.com/p/09c2375a39ad

码字很辛苦,转载请注明来自感触life-博客《用Laravel-modules模块化开发》

评论