3-19 4,720 views
假如你的项目要分离模块,比如说admin、shop、blog等等,你可能需要这个插件
详细文档:
https://nwidart.com/laravel-modules/.
https://packagist.org/packages/nwidart/laravel-modules
Laravel | laravel-modules |
---|---|
5.4 | ^1.0 |
5.5 | ^2.0 |
5.6 | ^3.0 |
5.7 | ^4.0 |
5.8 | ^5.0 |
安装
# install
$ composer require nwidart/laravel-modules
$ php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider"
#在composer添加"Modules\\": "Modules/"
{
"autoload": {
"psr-4": {
"App\\": "app/",
"Modules\\": "Modules/"
}
}
}
#运行
$ composer dump-autoload
注意事项
#lang
Lang::get('blog::group.name');
@trans('blog::group.name');
#view
view('blog::index')
view('blog::partials.sidebar')
#config
Config::get('blog.name')
命令
#创建模块
$ php artisan module:make Blog
目录结构
app/
bootstrap/
vendor/
Modules/
├── Blog/
├── Assets/
├── Config/
├── Console/
├── Database/
├── Migrations/
├── Seeders/
├── Entities/
├── Http/
├── Controllers/
├── Middleware/
├── Requests/
├── Providers/
├── BlogServiceProvider.php
├── RouteServiceProvider.php
├── Resources/
├── assets/
├── js/
├── app.js
├── sass/
├── app.scss
├── lang/
├── views/
├── Routes/
├── api.php
├── web.php
├── Repositories/
├── Tests/
├── composer.json
├── module.json
├── package.json
├── webpack.mix.js