PHP code example of ngodingskuyy / laravel-module-generator

1. Go to this page and download the library: Download ngodingskuyy/laravel-module-generator 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/ */

    

ngodingskuyy / laravel-module-generator example snippets




// Auto-load module routes
if (file_exists(__DIR__ . '/modules.php')) {
    



use App\Http\Controllers\ProductController;
use Illuminate\Support\Facades\Route;

Route::middleware(['auth', 'verified'])->group(function () {
    Route::resource('products', ProductController::class);
    Route::get('products/{product}/history', [ProductController::class, 'history'])->name('products.history');
});

// tests/Feature/{Name}Test.php
class ProductTest extends TestCase
{
    /** @test */
    public function it_can_list_products() { /* ... */ }
    
    /** @test */  
    public function it_can_create_product() { /* ... */ }
    
    /** @test */
    public function it_can_update_product() { /* ... */ }
    
    /** @test */
    public function it_can_delete_product() { /* ... */ }
}
bash
php artisan make:feature User
bash
php artisan make:feature User --force
bash
php artisan delete:feature User
bash
php artisan delete:feature User --with=factory,policy,observer,enum,test
bash
php artisan delete:feature User --force
bash
php artisan modules:setup
bash
php artisan modules:install

routes/
├── web.php
├── modules.php          # Auto-loader file
└── Modules/
    ├── Users/
    │   └── web.php      # Automatically loaded
    ├── Products/
    │   └── web.php      # Automatically loaded
    └── Orders/
        └── web.php      # Automatically loaded
bash
# Models
app/Models/{Name}.php

# Controllers  
app/Http/Controllers/{Name}Controller.php

# Requests
app/Http/Requests/{Name}/Store{Name}Request.php
app/Http/Requests/{Name}/Update{Name}Request.php

# Vue Components
resources/js/Pages/{Name}/Index.vue
resources/js/Pages/{Name}/Create.vue
resources/js/Pages/{Name}/Edit.vue
resources/js/Pages/{Name}/Show.vue

# Database
database/migrations/{timestamp}_create_{name}_table.php

# Routes
routes/{name}.php

# Seeders
database/seeders/{Name}PermissionSeeder.php
bash
routes/modules.php    # Main modules loader file
bash
# Create modules loader
php artisan setup:modules-loader

# Force overwrite existing file
php artisan setup:modules-loader --force
bash
# Install modules loader into Laravel routing
php artisan install:modules-loader

# Force reinstall even if already present
php artisan install:modules-loader --force
bash
routes/
├── web.php                 # Main Laravel routes (── modules/               # Your modular routes directory
    ├── products.php       # Product feature routes
    ├── users.php          # User feature routes
    ├── admin/             # Admin module subdirectory
    │   ├── dashboard.php  # Admin dashboard routes
    │   └── reports.php    # Admin reports routes
    └── api/               # API module subdirectory
        ├── v1.php         # API v1 routes
        └── v2.php         # API v2 routes
bash
# Solution: Check modules.php exists and is 
bash
# Check if commands are registered
php artisan list | grep "make:feature\|delete:feature\|setup:modules\|install:modules"

# Verify file generation
php artisan make:feature TestFeature --force
ls -la app/Models/TestFeature.php
php artisan delete:feature TestFeature --force
bash
   # Ensure PHP 8.2+ is installed
   php -v
   
bash
   composer dump-autoload
   php artisan config:clear
   php artisan cache:clear