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

 

posted @ 2019-10-21 17:54  苦瓜糖水  阅读(865)  评论(0编辑  收藏  举报