Laravel5.5 配置多模块

安装依赖

cd /var/www/html/blog
composer require caffeinated/modules

编辑配置文件config/app.php,注册服务器提供者和门面

# 在 providers 配置项中添加注册服务提供者

'providers' => [

    ......

    Caffeinated\Modules\ModulesServiceProvider::class,

    .....

]

# 在 alias 配置项中添加注册门面

'aliases'=>[

    ......

    'Module' => Caffeinated\Modules\Facades\Module::class

]

生成模块

cd /var/www/html/blog
php artisan make:module Base

root@shfumio:/var/www/html/erp# php artisan make:module Base
*-----------------------------------------------*
|                                               |
|              Copyright (c) 2016               |
|                  Shea Lewis                   |
|                                               |
|         Thanks for using Caffeinated!         |
*-----------------------------------------------*
______  ___     _________      ______
___   |/  /___________  /___  ____  /____________
__  /|_/ /_  __ \  __  /_  / / /_  /_  _ \_  ___/
_  /  / / / /_/ / /_/ / / /_/ /_  / /  __/(__  )
/_/  /_/  \____/\__,_/  \__,_/ /_/  \___//____/  

*-----------------------------------------------*
|                                               |
|          Step #1: Configure Manifest          |
|                                               |
*-----------------------------------------------*


 Please enter the name of the module: [Base]:
 > Base

 Please enter the slug for the module: [base]:
 > base

 Please enter the module version: [1.0]:
 > 1.0

 Please enter the description of the module: [This is the description for the Erp module.]:
 > base

You have provided the following manifest information:
Name:                       Base
Slug:                       base
Version:                    1.0
Description:                base
Basename (auto-generated):  Base
Namespace (auto-generated): App\Modules\Base

 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.
 

此时,在app/Modules下有一个Base的文件夹

访问域名  xxxx.com/base

出现默认提示

"This is the Base module index page. Build something great!"

创建控制器

app/Modules/Base/Http/Controllers

IndexControllers.php

<?php

namespace App\Modules\Erp\Http\Controllers;
use App\Http\Controllers\Controller;
class IndexController extends Controller{
    public function index(){
        echo 'sss';
        return view('base::Index.index');
    }
}

 创建模板

app\Modules\Base\Resources\Views\Index\index.blade.php

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
hello world
</body>
</html>

修改F:app\Modules\Base\Routes\web.php

<?php

Route::group(['prefix' => 'base'], function () {
    Route::get('/', function () {
        dd('This is the Base module index page. Build something great!');
    });
    Route::get('/index','IndexController@index');
});

猜你喜欢

转载自blog.csdn.net/qq_38157006/article/details/89952489