PHP code example of kadevland / laravel-easy-modules

1. Go to this page and download the library: Download kadevland/laravel-easy-modules library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kadevland / laravel-easy-modules example snippets


// bootstrap/providers.php (automatically updated)
return [
    App\Providers\AppServiceProvider::class,
    App\Modules\Blog\Providers\BlogServiceProvider::class, // ← Auto-added
];

// bootstrap/providers.php
return [
    App\Providers\AppServiceProvider::class,
    App\Modules\Blog\Providers\BlogServiceProvider::class,
    App\Modules\User\Providers\UserServiceProvider::class,
    // Add your modules here
];

// bootstrap/providers.php
return [
    App\Providers\AppServiceProvider::class,
    // App\Modules\Blog\Providers\BlogServiceProvider::class, // ← Disabled
    App\Modules\User\Providers\UserServiceProvider::class,
];

return [
    // Module location and namespace
    'base_path' => app_path('Modules'),
    'base_namespace' => 'App\\Modules',

    // Laravel 12 auto-discovery
    'auto_discover' => true,

    // Custom paths per component
    'paths' => [
        'controller' => 'Presentation/Http/Controllers',
        'model' => 'Infrastructure/Models',
        'entity' => 'Domain/Entities',
        // ... fully customizable
    ],

    // Custom stubs for flexible architecture
    'stubs' => [
        'controller' => 'easymodules/controller.stub',
        'entity' => 'easymodules/entity.stub',
        'dto' => 'easymodules/dto.stub',
        'repository' => 'easymodules/repository.stub',
        // ... your custom templates
    ]
];

// app/Modules/Blog/config/config.php
return [
    'name' => 'Blog',
    'enabled' => true,

    // Your custom settings
    'posts_per_page' => 10,
    'cache_ttl' => 3600,
    'features' => [
        'comments' => true,
        'categories' => true,
        'seo' => true,
    ],
    'seo' => [
        'meta_length' => 160,
        'slug_separator' => '-',
    ],
];

// Access in your code
config('blog.posts_per_page'); // 10
config('blog.features.comments'); // true

uses(Tests\TestCase::class)->in('Feature', 'Unit');
uses(Tests\TestCase::class)->in('app/Modules/*/Tests/Feature');
uses(Tests\TestCase::class)->in('app/Modules/*/Tests/Unit');

// app/Modules/Blog/config/config.php
return [
    'name' => 'Blog',
    'enabled' => true,
    'posts_per_page' => 15,
    'cache' => [
        'posts_ttl' => 3600,
        'categories_ttl' => 7200,
    ],
    'features' => [
        'comments' => true,
        'tags' => true,
        'seo' => true,
        'social_sharing' => true,
    ],
    'seo' => [
        'meta_description_length' => 160,
        'slug_separator' => '-',
        'auto_generate_meta' => true,
    ],
];
bash
# Single module
php artisan easymodules:new Blog

# Multiple modules
php artisan easymodules:new Blog User Product

# Using aliases
php artisan emodules:new Shop
php artisan emodule:new Auth
xml
<testsuites>
    <testsuite name="Feature">
        <directory suffix="Test.php">./tests/Feature</directory>
        <directory suffix="Test.php">./app/Modules/*/Tests/Feature</directory>
    </testsuite>
    <testsuite name="Unit">
        <directory suffix="Test.php">./tests/Unit</directory>
        <directory suffix="Test.php">./app/Modules/*/Tests/Unit</directory>
    </testsuite>
</testsuites>
js
export default {
    content: [
        "./resources/**/*.blade.php",
        "./resources/**/*.js",
        "./resources/**/*.vue",
        "./app/**/*.php",

        // Laravel Easy Modules with Clean Architecture
        "./app/Modules/*/Presentation/resources/views/**/*.blade.php",
        "./app/Modules/*/Presentation/resources/**/*.js",
        "./app/Modules/*/Presentation/resources/**/*.vue",
        "./app/Modules/*/Presentation/Views/Components/**/*.php",
    ],
    theme: {
        extend: {},
    },
    plugins: [],
};
bash
php artisan easymodules:new Blog
bash
# Create separate modules for clean domain separation
php artisan easymodules:new Product Order Payment User Cart Inventory