Laravel 模块化开发模块 – Caffienate

Laravel多模块配置
1. 安装对应版本"caffeinated/modules"
composer require caffeinated/modules 相应版本号
Laravel版本 | caffeinated/modules版本 |
5.0 | v1.2.3 |
5.1 | v2.0.1 - v3.2.5 |
5.2 | v2.2 - v3.2.5 |
5.3 | v4.0 - v4.1.6 |
5.4 | v4.2 - v4.2.1 |
5.5 | v4.2.2, v4.3.2 |
5.6 | v4.3 - v4.3.2 |
5.7 | v4.4 - v5.0.2 |
5.8 | v5.1.0 - v5.2.0 |
6.0 | v5.2.0 - v6.0.1 |
2. 生成配置文件
php artisan vendor:publish --provider="Caffeinated\Modules\ModulesServiceProvider" --tag="config"
执行命令后会在config文件夹中生成modules.php
3. 引入服务提供者与别名
进入文件config/app.php,添加以下内容:
// 找到providers数组在尾部添加代码 Caffeinated\Modules\ModulesServiceProvider::class
// 找到aliases数组在尾部添加代码 'Module' => Caffeinated\Modules\Facades\Module::class,
4. 创建新模块
php artisan make:module 模块名称
kuguats@kuguats-vb:/var/www/jx3box-helper$ php artisan make:module admin *-----------------------------------------------* | | | Copyright (c) 2016 | | Shea Lewis | | | | Thanks for using Caffeinated! | *-----------------------------------------------* ______ ___ _________ ______ ___ |/ /___________ /___ ____ /____________ __ /|_/ /_ __ \ __ /_ / / /_ /_ _ \_ ___/ _ / / / / /_/ / /_/ / / /_/ /_ / / __/(__ ) /_/ /_/ \____/\__,_/ \__,_/ /_/ \___//____/ *-----------------------------------------------* | | | Step #1: Configure Manifest | | | *-----------------------------------------------* Please enter the name of the module: [Admin]: > Please enter the slug for the module: [admin]: > Please enter the module version: [1.0]: > Please enter the description of the module: [This is the description for the Admin module.]: > You have provided the following manifest information: Name: Admin Slug: admin Version: 1.0 Description: This is the description for the Admin module. Basename (auto-generated): Admin Namespace (auto-generated): App\Modules\Admin If the provided information is correct, type "yes" to generate. (yes/no) [no]: > yes Thanks! That's all we need. Now relax while your module is generated. 2/2 [============================] 100% Module generated successfully.
5. 命名空间
添加视图命名空间
// 可以在服务提供者register方法内添加代码 View::addNamespace('{命名空间名}', '{视图模板文件夹路径}'); // 当调用视图时 return view("admin::index.index"); // 会先检索resources/views/vendor/admin上是否存在视图文件 // 如果不存对应视图则继续检索app/Modules/admin/Resources/Views
6. 相关命令
make:module make:module:controller make:module:migration make:module:request make:module:test module:disable module:enable module:list module:migrate module:migrate:refresh module:migrate:reset module:migrate:rollback module:seed
Try
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?