teksite/module
最新稳定版本:2.0.4
Composer 安装命令:
composer require teksite/module
包简介
a package to create modules for a laravel project
README 文档
README
A robust Laravel package designed to enable modularity, allowing you to organize your application into reusable, self-contained modules with commands similar to Laravel's native artisan commands.
Table of Contents
About
The Modular Laravel Package (teksite/module) brings modularity to Laravel applications, enabling developers to create self-contained modules with their own controllers, models, views, and more. It mirrors Laravel's native artisan commands but prepends module: to distinguish module-specific commands. Modules are stored in the Lareon/Modules directory, which replicates a miniature Laravel structure for each module.
Example
To create a controller in a specific module:
php artisan module:make-controller ExampleController ExampleModule --resource
Author
Developed by Sina Zangiband.
Contact
- Website: teksite.net
- Email: sina.zangiband@gmail.com
Installation
Compatibility
| Laravel | Package |
|---|---|
| 11.x | ^1.0 |
| 12.x | ^2.0 |
Step 1: Install via Composer
Run the following command in your terminal:
composer require teksite/module
Note on wikimedia/composer-merge-plugin
If prompted with:
Do you trust "wikimedia/composer-merge-plugin" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?]
Press y and Enter. This plugin is required to merge composer.json files from modules.
Step 2: Register the Service Provider
Note: Laravel 5.5 and above supports auto-discovery, so this step is optional for newer versions.
For Laravel 10 and 11
Add the service provider to bootstrap/providers.php:
<?php return [ // Other providers Teksite\Module\ModuleServiceProvider::class, ];
For Laravel 5.x and Earlier
Add the service provider to config/app.php under the providers array:
'providers' => [ // Other Service Providers Teksite\Module\ModuleServiceProvider::class, ],
Step 3: Publish Configuration (Optional)
Publish the package's configuration file for customization:
php artisan vendor:publish --provider="Teksite\Module\ModuleServiceProvider"
Step 4: Update Composer.json
To autoload module classes, add the following to your composer.json:
"extra": { "laravel": { "dont-discover": [] }, "merge-plugin": { "include": [ "Lareon/Modules/*/composer.json" ] } }
Step 5: Refresh Autoloader
Run the following command to refresh Composer's autoloader:
composer dump-autoload
Usage
Creating a Module
Generate a new module with a structure similar to Laravel's:
php artisan module:make Example
This creates a new module in Lareon/Modules/Example with directories like Controllers, Models, Views, etc.
Module Commands
The package supports Laravel-like artisan commands prefixed with module:. Examples include:
- Create a controller:
php artisan module:make-controller ExampleController ExampleModule --resource
- Create a model:
php artisan module:make-model ExampleModel ExampleModule --migration
- Create a middleware:
php artisan module:make-middleware ExampleMiddleware ExampleModule
Changing Module Priority
To adjust the loading order of modules, modify the bootstrap/modules.php file. Reorder the modules array to prioritize specific modules:
<?php return [ 'Blog' => [ 'provider' => 'Lareon\\Modules\\Blog\\App\\Providers\\BlogServiceProvider', 'active' => true, 'type' => 'lareon', ], 'Page' => [ 'provider' => 'Lareon\\Modules\\Page\\App\\Providers\\PageServiceProvider', 'active' => true, 'type' => 'self', ], ];
Integration with Lareon
If you use the teksite/lareon package, you can create modules controlled by Lareon using:
php artisan module:make Example --lareon
To switch an existing module between Lareon-controlled (lareon) and self-managed (self), update the type in bootstrap/modules.php:
'Example' => [ 'provider' => 'Lareon\\Modules\\Example\\App\\Providers\\ExampleServiceProvider', 'active' => true, 'type' => 'lareon', // or 'self' ],
Warning: Manually changing the
typemay cause issues. Ensure compatibility when switching.
Credits
License
This package is open-sourced under the MIT License. See the License File for details.
Support
For questions, issues, or feature requests, please reach out via:
- Website: teksite.net
- Email: sina.zangiband@gmail.com
- GitHub Issues: teksite/module
Contributions are welcome! Feel free to submit a pull request or open an issue on GitHub.
统计信息
- 总下载量: 29
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-01-25