laravel-modular maintained by dev-sajid
Description
Lightweight Laravel modularization: drop-in modules under modules/ with auto-discovery, no external dependencies.
Author
Last update
2025/08/23 21:42
(dev-master)
License
Downloads
1
Tags
Laravel Modular v2.0
Lightweight module system for Laravel 11+ applications. Drop modules under modules/{Name} and they are auto-discovered with zero configuration.
Features
- 🚀 Zero Dependencies: No external packages required
- 🔍 Auto-Discovery: Modules are automatically discovered and registered
- 📦 Convention-based: Follow simple naming conventions for instant setup
- 🎯 Laravel 11+ Compatible: Built for modern Laravel applications
- 🛠️ Artisan Integration: Generate modules with
php artisan make:module - 📁 Flexible Structure: Support for routes, views, migrations, config, translations, and more
- ⚡ High Performance: Lightweight with minimal overhead
Requirements
- PHP 8.2 or higher
- Laravel 11.0 or higher
Installation
Install the package via Composer:
composer require dev-sajid/laravel-modular
The package will auto-register thanks to Laravel's package auto-discovery.
Quick Start
-
Generate a module:
php artisan make:module Blog -
Your module structure:
modules/ └── Blog/ ├── BlogServiceProvider.php ├── Http/ │ └── Controllers/ │ └── BlogController.php ├── routes/ │ └── web.php ├── resources/ │ └── views/ │ └── index.blade.php ├── Database/ │ └── migrations/ │ └── 2025_08_24_000000_create_blogs_table.php └── lang/ -
Run migrations:
php artisan migrate -
Access your module: Visit
/blogin your browser!
Configuration
Publish the configuration file (optional):
php artisan vendor:publish --tag=modular-config
This creates config/modular.php:
<?php
return [
// Directory where modules are stored
'modules_path' => 'modules',
// Base namespace for modules
'namespace' => 'Modules',
// Whether to prefer module-specific ServiceProviders
'prefer_module_provider' => true,
];
Module Structure
Each module can contain:
modules/YourModule/
├── YourModuleServiceProvider.php # Optional custom service provider
├── Http/
│ └── Controllers/ # Controllers
├── routes/
│ ├── web.php # Web routes
│ └── api.php # API routes (optional)
├── resources/
│ └── views/ # Blade templates
├── Database/
│ └── migrations/ # Database migrations
├── lang/ # Translations
├── config/ # Module-specific config files
└── helpers.php # Helper functions (optional)
Examples
Creating a Blog Module
php artisan make:module Blog
Generated controller (modules/Blog/Http/Controllers/BlogController.php):
<?php
namespace Modules\Blog\Http\Controllers;
use Illuminate\Routing\Controller;
class BlogController extends Controller
{
public function index()
{
return view('blog::index');
}
}
Upgrading from v1.x
Version 2.0 includes several breaking changes:
Requirements
- PHP: Now requires 8.2+ (was 8.1+)
- Laravel: Now requires 11.0+ (was 10.0+)
To upgrade:
- Update your
composer.jsonto require PHP 8.2+ - Update to Laravel 11+
- Run
composer update dev-sajid/laravel-modular
License
The MIT License (MIT). Please see License File for more information.