PHPackages                             nirajkhadka/laravel-module-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Admin Panels](/categories/admin)
4. /
5. nirajkhadka/laravel-module-generator

ActiveLibrary[Admin Panels](/categories/admin)

nirajkhadka/laravel-module-generator
====================================

A Laravel package that generates complete CRUD modules with controllers, services, actions, DTOs, form requests, models, and migrations using artisan commands.

v1.0.0(10mo ago)2121MITPHPPHP ^8.1|^8.2|^8.3|^8.4

Since Jun 21Pushed 10mo agoCompare

[ Source](https://github.com/Nirajkhad/niraj-laravel-module-generator)[ Packagist](https://packagist.org/packages/nirajkhadka/laravel-module-generator)[ Docs](https://github.com/Nirajkhad/laravel-module-generator)[ RSS](/packages/nirajkhadka-laravel-module-generator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

Laravel Module Generator
========================

[](#laravel-module-generator)

A Laravel package that quickly generates complete CRUD modules including Controllers, Services, Actions, DTOs, Form Requests, Models, Migrations, and Resources via a single Artisan command.

---

Why Use This Package?
---------------------

[](#why-use-this-package)

Creating CRUD modules repeatedly can be tedious. This package scaffolds all the essential files you need to get started with clean, maintainable, and consistent code architecture — so you can focus on business logic instead of boilerplate.

---

Features
--------

[](#features)

- Generate Controllers, Services, and Action classes for CRUD operations
- Generate Data Transfer Objects (DTOs) for data handling
- Generate Form Request classes with validation
- Generate Eloquent Models with UUID support
- Generate timestamped database migration files
- Generate API Resource classes for consistent JSON responses
- Support for nested modules with proper namespaces
- Configurable base namespace and paths
- Stub files can be published and customized

---

Installation
------------

[](#installation)

Require the package via Composer:

```
composer require nirajkhadka/laravel-module-generator --dev
```

Publish configuration and stubs:

```
php artisan vendor:publish --tag=module-generation-config
php artisan vendor:publish --tag=module-generator-stubs
```

---

Usage
-----

[](#usage)

Generate a new module with:

```
php artisan module:make {ModuleName}
```

Example:

```
php artisan module:make Customer
```

This command creates:

- Controller (`CustomerController.php`)
- Service (`CustomerService.php`)
- Actions: Index, Store, Update, Delete
- DTO (`CustomerDto.php`)
- Requests: Index, Store, Update
- Model (`Customer.php`)
- Migration file for the table
- API Resource (`CustomerResource.php`)

### Nested Modules

[](#nested-modules)

You can specify nested namespaces by using slashes:

```
php artisan module:make Admin/Customer
```

This generates the module under `App\Http\Controllers\Admin`, `App\Services\Admin`, etc.

---

Configuration
-------------

[](#configuration)

Modify the published config file `config/module-generation-module.php` to customize:

- Base namespace
- Paths for controllers, services, actions, DTOs, and requests

---

Customizing Stubs
-----------------

[](#customizing-stubs)

Customize generated files by modifying the stub files located at:

```
stubs/vendor/module-generator-stubs

```

Publish stubs to your project by running the vendor publish command (shown above).

---

Contributing
------------

[](#contributing)

Feel free to open issues or submit pull requests on the [GitHub repo](https://github.com/Nirajkhad/niraj-laravel-module-generator).

---

License
-------

[](#license)

MIT License © Niraj Khadka

---

Author
------

[](#author)

Niraj Khadka
Email:
GitHub: [Nirajkhad](https://github.com/Nirajkhad/)

---

### Usage Examples

[](#usage-examples)

#### Basic Module Generation

[](#basic-module-generation)

Generate a simple module named Product:

```
php artisan module:make Product
```

This creates:

- `app/Http/Controllers/ProductController.php`
- `app/Services/ProductService.php`
- Actions: `IndexAction.php`, `StoreAction.php`, `UpdateAction.php`, `DeleteAction.php`
- DTO: `ProductDto.php`
- Requests: `IndexRequest.php`, `StoreRequest.php`, `UpdateRequest.php`
- Model: `Product.php`
- Migration: timestamped `create_products_table.php`
- API Resource: `ProductResource.php`

#### Nested Module with Namespace

[](#nested-module-with-namespace)

Generate a nested module `Admin/User` with namespacing:

```
php artisan module:make Admin/User
```

Creates:

- `app/Http/Controllers/Admin/UserController.php`
- `app/Services/Admin/UserService.php`
- Actions inside `app/Actions/Admin/User/`
- Requests inside `app/Http/Requests/Admin/User/`
- Model: `app/Models/Admin/User.php` (if your config supports nested models)
- Migration and resources properly namespaced

This keeps code organized in subfolders and namespaces.

#### Customizing Namespace and Paths

[](#customizing-namespace-and-paths)

Publish the config file:

```
php artisan vendor:publish --tag=module-generation-config
```

Then edit `config/module-generation-module.php`:

```
return [
    'base_namespace' => 'App',
    'paths' => [
        'controllers' => 'Http/Controllers/Custom',
        'services' => 'Domain/Services',
        'actions' => 'Domain/Actions',
        'dtos' => 'Domain/Dtos',
        'requests' => 'Http/Requests/Custom',
    ],
];
```

Now when you run `module:make Product`, files will generate inside your custom directories.

---

### FAQ

[](#faq)

**Q: Can I generate only specific parts of the module?**
A: Currently, the package generates the full CRUD module at once. Selective generation may be planned for future versions.

**Q: How do I override stub templates?**
A: Run:

```
php artisan vendor:publish --tag=module-generator-stubs
```

This publishes stub files to `stubs/vendor/module-generator-stubs/`. Modify these `.stub` files to customize generated code templates.

**Q: Will this work with Laravel versions below 9?**
A: No, it requires Laravel 9 or higher due to dependencies and PHP 8.1+ features.

**Q: How do I change UUID generation or disable it?**
A: Modify the model stub in your published stubs directory. You can change or remove the `HasUuids` trait and UUID logic as needed.

**Q: How to add additional fields to the migration?**
A: Edit the migration stub after publishing, or manually add columns after generation.

---

### Troubleshooting Tips

[](#troubleshooting-tips)

- **Command Not Found:** Ensure package is installed via Composer and `ModuleServiceProvider` is registered (auto-discovered by default).
- **Stubs Not Publishing:** Check write permissions on your `stubs/` directory and run the publish command again.
- **Namespace Issues:** Verify the `base_namespace` and paths in the config file match your Laravel app structure.
- **Migration Timestamp Conflicts:** If migration with the same name exists, you will be prompted to overwrite or skip.
- **Model Not Found in Controller:** Check your namespace configurations, especially if you use nested modules.

---

### Code Snippets for Extending or Modifying Generated Modules

[](#code-snippets-for-extending-or-modifying-generated-modules)

#### Adding a New Method to the Service

[](#adding-a-new-method-to-the-service)

Open the generated service, e.g., `app/Services/ProductService.php` and add:

```
public function getByName(string $name): ?Product
{
    return Product::where('name', $name)->first();
}
```

#### Adding Custom Validation to Requests

[](#adding-custom-validation-to-requests)

Modify `StoreRequest.php`:

```
public function rules(): array
{
    return [
        'name' => ['required', 'string', 'min:3', 'unique:products,name'],
        'price' => ['required', 'numeric', 'min:0'],
    ];
}
```

Add new fields accordingly in DTO and migration stubs as well.

#### Extending Controller with a Custom Endpoint

[](#extending-controller-with-a-custom-endpoint)

In `ProductController.php`, add:

```
public function search(Request $request)
{
    $name = $request->input('name');

    $product = $this->productService->getByName($name);

    if (!$product) {
        return response()->json(['message' => 'Product not found'], 404);
    }

    return response()->json(['data' => ProductResource::make($product)]);
}
```

Add a route to `routes/api.php`:

```
Route::get('products/search', [ProductController::class, 'search']);
```

---

### Customizing Stub Files

[](#customizing-stub-files)

After publishing stubs, edit any `.stub` file inside `stubs/vendor/module-generator-stubs/` such as `controller.stub`:

Replace placeholders or add custom traits, imports, or methods that fit your coding style or project standards.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance56

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

322d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a95e28315dc43715da3d865da8fa1081a9373571d77d43159aaffdd26ec67f20?d=identicon)[Nirajkhad](/maintainers/Nirajkhad)

---

Top Contributors

[![Nirajkhad](https://avatars.githubusercontent.com/u/86679585?v=4)](https://github.com/Nirajkhad "Nirajkhad (16 commits)")

---

Tags

artisanboilerplatecode-generatorcrudgeneratorlaravelmodulephp8scaffoldphplaravelgeneratorcode generatorscaffoldartisanmodulecrudboilerplate

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/nirajkhadka-laravel-module-generator/health.svg)

```
[![Health](https://phpackages.com/badges/nirajkhadka-laravel-module-generator/health.svg)](https://phpackages.com/packages/nirajkhadka-laravel-module-generator)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
