erlandmuchasaj/laravel-modules
Composer 安装命令:
composer require erlandmuchasaj/laravel-modules
包简介
Laravel modules management.
README 文档
README
A very simple autowired laravel modules generator using laravel best practices and folder structure. If you like laravel, you will love laravel modules and feel just like home.
It follows the same folder structure as a Laravel project, the only difference is instead of app/, you have src/, the rest is same.
Installation
You can install the package via composer:
composer require erlandmuchasaj/laravel-modules
Usage
Basically this is all you need to do is generate a new module.
php artisan module:make <ModuleName>
When you generate a new module, it will auto register himself automatically by adding the module to the required
list in composer.json file
"require": { "modules/{{module_name}}": "^1.0" },
And also it will add automatically repositories
"repositories": [ { "type": "path", "url": "./modules/*" } ]
and it will run composer update in the background to discover the newly generated module,
and you are good to go.
Creating new module
Here everything is done inside a Module. Basically one module is a Laravel within another Laravel application with all its components, views, routes, middleware, events, database, seeders, factories and much, much more.
php artisan module:make <ModuleName>
- The module is auto-discovered so there is no need to add it to app/config.php providers list.
- Then run
composer updateand you are good to go (even this is run automatically when you add modulevia php artisan module:make <ModuleName>).
Artisan commands
php artisan module:list Show list of all modules created. php artisan module:make Create blueprint for a new module php artisan module:make-cast Create a new custom Eloquent cast class php artisan module:make-channel Create a new channel class php artisan module:make-command Create a new Artisan command php artisan module:make-component Create a new component-class for the specified module. php artisan module:make-controller Create a new controller class php artisan module:make-event Create a new event class php artisan module:make-exception Create a new custom exception class php artisan module:make-factory Create a new model factory php artisan module:make-job Create a new job class php artisan module:make-listener Create a new event listener class php artisan module:make-mail Create a new email class php artisan module:make-middleware Create a new middleware class php artisan module:make-migration Create a new migration file for module. php artisan module:make-model Create a new Eloquent model class php artisan module:make-notification Create a new notification class php artisan module:make-observer Create a new observer class php artisan module:make-policy Create a new policy class php artisan module:make-provider Create a new service provider class php artisan module:make-request Create a new form request class php artisan module:make-resource Create a new resource php artisan module:make-rule Create a new validation rule php artisan module:make-scope Create a new scope class php artisan module:make-seeder Create a new seeder class php artisan module:make-test Create a new test class php artisan module:make-trait Make trait
If you want to register Events, Policies, Observers, Middleware, Commands, Providers etc. you can do so on
./modules/ModuleName/Providers/EventServiceProvider and ./modules/ModuleName/Providers/AppServiceProvider
Examples:
Registering new provider. Go to ./modules/ModuleName/Providers/AppServiceProvider and add the provider to
$providers array as follows:
/** * Get the services provided by the provider. * * @var array<int, class-string> */ protected array $providers = [ ... NewServiceProvider::class, // <= new provider added here ];
Subscribing and/or listening to events. Go to ./modules/ModuleName/Providers/EventServiceProvider and on the
$subscribe array add the EventSubscriber listener:
/** * Class event subscribers. * * @var array<int, class-string> */ protected $subscribe = [ AnnouncementEventListener::class ];
Or you can just listen to events as you normally would in Laravel:
/** * The event listener mappings for the application. * * @var array<class-string, array<int, class-string>> */ protected $listen = [ Registered::class => [ SendEmailVerificationNotification::class, ], ];
Adding new policy. Go to ./modules/ModuleName/Providers/AppServiceProvider and add to $policies array the Model
and corresponding Policy as follows:
/** * The policy mappings for the application. * Announcement::class is the model <== * * @var array<class-string, class-string> */ protected array $policies = [ Announcement::class => AnnouncementPolicy::class, ];
Adding new observer. Go to ./modules/ModuleName/Providers/AppServiceProvider and add to $observers array the
Model and the corresponding Observer as follows:
/** * The policy mappings for the application. * Announcement::class is the model <== * * @var array<class-string, class-string> */ protected array $policies = [ Announcement::class => AnnouncementObserver::class, ];
Adding new command. Go to ./modules/ModuleName/Providers/AppServiceProvider and add to $commands array the name
of the command as follows:
/** * The available command shortname. * * @var array<int, class-string> */ protected array $commands = [ AppVersion::class, SendAnnouncementNotifications::class ];
Middleware. There are 3 types of middleware that you can add. Global, Grouped and route.
/** * The application's global middleware stack. * * @var array<int, class-string> */ protected array $middleware = [ ... AddXHeader::class, // <== Add global middleware here ]; /** * The application's route middleware groups. * * @var array<string, array<int, class-string>> */ protected array $middlewareGroups = [ 'web' => [ RememberLocale::class, ], 'api' => [ IdempotencyMiddleware::class, ], // <== Add grouped middleware here. you can add to existing group or create new groups. ]; /** * The application's route middleware. * These middleware may be assigned to group or used individually. * * @var array<string, class-string> */ protected array $routeMiddleware = [ ... 'ip_whitelist' => IpWhitelist::class, // <== Add route middleware here ];
Support me
I invest a lot of time and resources into creating best in class open source packages.
If you found this package helpful you can show support by clicking on the following button below and donating some amount to help me work on these projects frequently.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please see SECURITY for details.
Credits
License
The MIT License (MIT). Please see License File for more information.
erlandmuchasaj/laravel-modules 适用场景与选型建议
erlandmuchasaj/laravel-modules 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 669 次下载、GitHub Stars 达 8, 最近一次更新时间为 2023 年 03 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「module」 「modules」 「hmvc」 「laravel」 「ddd」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 erlandmuchasaj/laravel-modules 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 erlandmuchasaj/laravel-modules 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 erlandmuchasaj/laravel-modules 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This is Paymorrow module for OXID eShop.
Analysis module for finding problematical shop data.
yii2 swiper slider
An interactive tour through the TYPO3 backend.
Simple ASCII output of array data
统计信息
- 总下载量: 669
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-15