dev-sajid/laravel-modular

Lightweight Laravel modularization: drop-in modules under modules/ with auto-discovery, no external dependencies.

2.0.0 2025-08-23 19:30 UTC

This package is auto-updated.

Last update: 2025-09-23 19:46:45 UTC


README

Latest Version on Packagist Total Downloads MIT Licensed

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

  1. Generate a module:

    php artisan make:module Blog
  2. 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/
    
  3. Run migrations:

    php artisan migrate
  4. Access your module: Visit /blog in 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:

  1. Update your composer.json to require PHP 8.2+
  2. Update to Laravel 11+
  3. Run composer update dev-sajid/laravel-modular

License

The MIT License (MIT). Please see License File for more information.