saeedvir/laravel-modular
Composer 安装命令:
composer require saeedvir/laravel-modular
包简介
A powerful modular architecture package for Laravel applications with auto-discovery, composer merge support, and comprehensive artisan commands
README 文档
README
A powerful modular architecture package for Laravel applications that allows you to organize your codebase into independent, reusable modules with automatic discovery and zero configuration.
✨ Features
-
📦 Zero Configuration - Modules are automatically discovered and registered via composer merge plugin
-
💾 Automatic Persistence - Module enable/disable states are automatically saved and restored
-
⚡ Performance Optimized - Built-in caching and lazy loading for production use
-
⚡ (saeedvir/laravel-modular 🆚 nWidart/laravel-modules) Peak memory: Improved by 23.1% and Memory usage improved by 10.2%
-
🎨 Complete Module Structure - Controllers, models, views, routes, migrations, translations
-
🔧 Artisan Commands - Comprehensive CLI tools for module management
-
📊 Performance Monitoring - Track module discovery and operation performance
-
🐛 Debug-Aware Logging - Respects
APP_DEBUGfor production-friendly logs -
🧪 Testing Support - Built-in infrastructure for module testing
-
🎯 Laravel 11 & 12 & 13 - Full support for modern Laravel versions
📋 Requirements
- PHP ^8.2 (PHP ^8.3 for Laravel 13)
- Laravel ^11.0, ^12.0, or ^13.0
- Composer
📦 Installation
Install the package via composer:
composer require saeedvir/laravel-modular
The package will automatically register itself via Laravel's package auto-discovery.
Configure composer merge plugin in your root composer.json:
{
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/",
"Module\\": "modules/"
}
},
"extra": {
"merge-plugin": {
"include": ["modules/*/composer.json"]
}
},
"config": {
"allow-plugins": {
"wikimedia/composer-merge-plugin": true
}
}
}
Publish the configuration file (optional):
php artisan vendor:publish --tag=module-config
📖 For detailed installation instructions, troubleshooting, and setup guide, see:
Installation Guide
🚀 Quick Start
Create Your First Module
php artisan module:make Blog composer dump-autoload
This creates a complete module structure:
modules/Blog/
├── app/
│ ├── Console/
│ ├── Http/
│ │ ├── Controllers/
│ │ ├── Middleware/
│ │ └── Requests/
│ ├── Models/
│ ├── Providers/
│ │ └── BlogServiceProvider.php
│ └── Services/
├── config/
│ └── config.php
├── database/
│ ├── migrations/
│ ├── seeders/
│ └── factories/
├── resources/
│ ├── views/
│ └── lang/
├── routes/
│ ├── web.php
│ └── api.php
└── composer.json
php artisan module:list
Check Module Status
php artisan module:status
Remove a Module
php artisan module:remove Blog
📖 Usage
Creating Controllers
php artisan module:controller Blog PostController
Creating Models
php artisan module:make-model Blog Post --migration --factory --seeder
This creates a model in modules/Blog/app/Models/Post.php and optionally generates the associated migration, factory, and seeder.
Alternatively, you can create models manually:
<?php namespace Modules\Blog\Models; use Illuminate\Database\Eloquent\Model; class Post extends Model { protected $fillable = ['title', 'content', 'slug']; }
Adding Routes
In modules/Blog/routes/web.php:
<?php use Illuminate\Support\Facades\Route; use Modules\Blog\Http\Controllers\PostController; // Routes are automatically prefixed with 'blog' Route::get('/', [PostController::class, 'index'])->name('index'); Route::resource('posts', PostController::class);
Note: All routes are automatically prefixed with the module name (
/blog/in this case). See Routing Guide for details.
Using Views
Create views in modules/Blog/resources/views/ and load them:
return view('blog::posts.index');
Migrations
Create migrations in your module:
php artisan module:make-migration Blog create_posts_table
Run migrations:
php artisan migrate
Testing
Generate a test for your module:
php artisan module:make-test Blog PostTest --feature
Run tests for a specific module or all modules:
php artisan module:test Blog php artisan module:test --all
🎯 Advanced Features
Module Configuration
Each module can have its own configuration file in config/config.php:
return [ 'name' => 'Blog', 'enabled' => true, 'version' => '1.0.0', // Your custom config... ];
Access module config:
config('blog.version');
Register Livewire Components in Module Service Providers
use Livewire\Livewire; public function boot(): void { //your codes $this->registerLivewireComponents(); //your codes } protected function registerLivewireComponents(): void { Livewire::component('admin::user-management', \Modules\Admin\Livewire\UserManagement::class); }
usage :
admin::livewire.admin-login
Disabling Modules
You can easily enable or disable modules using Artisan commands. These states are automatically persisted in modules/modules.json.
# Disable a module php artisan module:disable Blog # Enable a module php artisan module:enable Blog
Alternatively, you can manually list modules to be disabled in config/module.php:
'disabled' => [ 'OldModule', ],
Note: The persistent state in
modules.jsontakes precedence over theconfig/module.php'sdisabledarray.
Performance Optimization
The package includes built-in caching:
# Cache module discovery php artisan module:cache # Pre-calculate and optimize module discovery (recommended for production) php artisan module:optimize
Debug Mode
When APP_DEBUG=true, the package logs:
- Module discovery events
- Cache operations
- Module creation/deletion
- Performance metrics
When APP_DEBUG=false (production), only errors are logged.
🛠️ Available Commands
| Command | Description |
|---|---|
module:make |
Create a new module |
module:list |
List all modules |
module:remove |
Remove a module |
module:make-controller |
Create a controller in a module |
module:make-model |
Create a model in a module |
module:make-test |
Create a test class in a module |
module:make-request |
Create a form request in a module |
module:make-resource |
Create an API resource in a module |
module:make-migration |
Create a migration in a module |
module:make-factory |
Create a model factory in a module |
module:make-seeder |
Create a database seeder in a module |
module:enable |
Enable a specific module |
module:disable |
Disable a specific module |
module:status |
Show status of all modules |
module:test |
Run tests for a specific module |
module:cache |
Manage module discovery cache |
module:optimize |
Optimize module discovery for production |
⚙️ Configuration
The config/module.php file provides extensive configuration options:
return [ // Module storage path 'path' => base_path('modules'), // Disabled modules 'disabled' => [], // Caching 'cache' => [ 'enabled' => env('MODULE_CACHE_ENABLED', true), 'key' => 'laravel_modular_cache', 'lifetime' => 86400, // 24 hours ], // Auto-register routes 'auto_register_routes' => true, // Custom stubs path 'stubs_path' => null, ];
📚 Documentation
- Installation Guide - Complete installation and setup
- Routing Guide - Module routing and automatic prefixing ⭐
- Debug Logging - Debug mode and logging configuration
- Performance Optimization - Performance tips and caching
- Enhancement Summary - Feature enhancements and improvements
🆚 Comparison with nWidart/laravel-modules
Both packages provide modular architecture for Laravel, but with different approaches:
Laravel Modular (This Package)
Philosophy: Zero-configuration with native Composer integration
✅ Advantages:
- Zero Configuration - Uses
wikimedia/composer-merge-pluginfor automatic autoloading - Native Composer - Works with standard Composer workflows
- Automatic Discovery - No manual registration needed
- Performance Focused - Built-in caching and performance monitoring
- Debug-Aware Logging - Respects
APP_DEBUGfor production - Simpler Structure - Standard Laravel conventions
- Less Overhead - Minimal abstraction layer
- Composer-First - Each module has its own
composer.json
Best For:
- Projects that prefer Composer-native solutions
- Teams familiar with standard Laravel structure
- Applications requiring high performance
- Projects with frequent module changes
nWidart/laravel-modules
Philosophy: Feature-rich with extensive abstisan commands
✅ Advantages:
- More Commands - Extensive artisan command set
- Asset Management - Built-in asset publishing
- Module Status - Enable/disable modules dynamically
- Established - Mature package with large community
- More Features - Additional abstractions and helpers
Best For:
- Projects needing extensive CLI tools
- Applications with complex module management needs
- Teams wanting more built-in features
Feature Comparison
| Feature | Laravel Modular | nWidart/laravel-modules |
|---|---|---|
| Autoloading | Composer merge plugin | Custom autoloader |
| Setup Complexity | Minimal | Moderate |
| Module Discovery | Automatic | Manual registration |
| Performance | Optimized with caching | Standard |
| Composer Integration | Native | Custom |
| Debug Logging | Environment-aware | Standard |
| Learning Curve | Low (standard Laravel) | Moderate |
| Module Structure | Laravel conventions | Custom structure |
| Asset Management | Standard Laravel | Built-in system |
| CLI Commands | 17 essential commands | 40+ commands |
| Community | Growing | Established |
| Package Size | Lightweight | Full-featured |
When to Choose Laravel Modular
Choose this package if you:
- ✅ Want zero-configuration setup
- ✅ Prefer native Composer workflows
- ✅ Need optimal performance
- ✅ Like standard Laravel conventions
- ✅ Want minimal overhead
- ✅ Use
composer dump-autoloadworkflow
When to Choose nWidart/laravel-modules
Choose nWidart if you:
- ✅ Need extensive artisan commands
- ✅ Want built-in asset management
- ✅ Require dynamic module enable/disable
- ✅ Prefer feature-rich solutions
- ✅ Need established community support
Migration from nWidart
Migrating is straightforward:
- Module structure is similar (both use MVC)
- Routes and views work the same way
- Main difference is autoloading (Composer vs custom)
- Our Installation Guide covers setup
Both packages are excellent choices - pick based on your project's needs! 🎯
🧪 Testing
composer test
🤝 Contributing
Please see CONTRIBUTING for details on how to contribute to this project.
📝 Changelog
Please see CHANGELOG for more information on what has changed recently.
🔒 Security
If you discover any security-related issues, please email saeed.es91@gmail.com instead of using the issue tracker.
👥 Credits
📄 License
The MIT License (MIT). Please see License File for more information.
💡 Examples
Blog Module Example
// Controller namespace Modules\Blog\Http\Controllers; use Modules\Blog\Models\Post; class PostController extends Controller { public function index() { $posts = Post::latest()->paginate(10); return view('blog::posts.index', compact('posts')); } } // Model namespace Modules\Blog\Models; use Illuminate\Database\Eloquent\Model; class Post extends Model { protected $fillable = ['title', 'content', 'slug', 'published_at']; protected $casts = ['published_at' => 'datetime']; } // Route Route::prefix('blog')->group(function () { Route::resource('posts', PostController::class); });
🌟 Why Laravel Modular?
- Scalability: Organize large applications into manageable modules
- Reusability: Share modules across projects
- Maintainability: Clear separation of concerns
- Team Collaboration: Teams can work on different modules independently
- Performance: Optimized for production with caching and lazy loading
- Modern: Built for Laravel 11 & 12 with PHP 8.2+
📊 Performance
- Module Discovery: ~15-20ms (cached)
- Autoloading: Native composer PSR-4 (optimal performance)
- Memory Usage: Minimal overhead with lazy loading
- Production Ready: Designed for high-traffic applications
Built with ❤️ for the Laravel community
If you find this package helpful, please consider giving it a ⭐ on GitHub!
saeedvir/laravel-modular 适用场景与选型建议
saeedvir/laravel-modular 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 125 次下载、GitHub Stars 达 26, 最近一次更新时间为 2025 年 11 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「modules」 「laravel」 「modular」 「structure」 「organization」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 saeedvir/laravel-modular 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 saeedvir/laravel-modular 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 saeedvir/laravel-modular 相关的其它包
同方向 / 同关键字的高下载量 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
统计信息
- 总下载量: 125
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 27
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-05