PHPackages                             efati/laravel-scaffolder - 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. efati/laravel-scaffolder

ActiveLibrary[Admin Panels](/categories/admin)

efati/laravel-scaffolder
========================

Laravel Scaffolder - A powerful package for scaffolding complete feature stacks with Repository, Service, DTO, Policy, Tests, and more.

v8.0.9(5mo ago)28MITPHPPHP ^8.1CI failing

Since Dec 2Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/AfshinEfati/Laravel-Scaffolder)[ Packagist](https://packagist.org/packages/efati/laravel-scaffolder)[ Docs](https://github.com/AfshinEfati/Laravel-Scaffolder)[ RSS](/packages/efati-laravel-scaffolder/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

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

[](#laravel-module-generator)

[![Docs Deployment Status](https://github.com/AfshinEfati/Laravel-Scaffolder/actions/workflows/docs.yml/badge.svg?branch=main)](https://github.com/AfshinEfati/Laravel-Scaffolder/actions/workflows/docs.yml)

📖 Documentation
---------------

[](#-documentation)

**Full documentation:** 👉 [Laravel Module Generator Docs](https://afshinefati.github.io/Laravel-Scaffolder/)

---

Generate complete, test-ready Laravel modules from a single Artisan command. The generator scaffolds repositories, services, DTOs, controllers, API resources, form requests, feature tests, and supporting helpers so you can jump straight to business logic.

> **Compatible with Laravel 10 &amp; 11 · Requires PHP 8.1+**

Why this package?
-----------------

[](#why-this-package)

- **Schema-aware scaffolding** – infer metadata from existing migrations or inline `--fields` definitions to pre-fill DTOs, validation rules, and test payloads.
- **End-to-end module wiring** – repositories, services, and providers are generated together and the provider is auto-registered.
- **API-first controllers** – generate API controllers with form requests and resources by default, or switch to web controllers via config.
- **Action layer support** – optional invokable action classes for clean separation of concerns.
- **Opinionated feature tests** – CRUD tests exercise success and failure flows using inferred field metadata.
- **Jalali date tooling** – built-in `goli()` helper and Carbon macros for Persian calendar support.
- **✨ Built-in API Docs** – generate OpenAPI documentation **without L5-Swagger or any external packages**!
- **Module-scoped requests** – form requests live under `Http/Requests/{Module}` for better organization.

Requirements
------------

[](#requirements)

- PHP 8.1 or newer
- Laravel framework 10.x or 11.x
- ✅ **No external dependencies** – API documentation included!

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

[](#installation)

Require the package and let the generator mirror its base assets automatically during console boot:

```
composer require efati/laravel-scaffolder --dev
```

The service provider copies the default repositories, services, helper, and configuration into your application whenever the package runs in the console, so there is no extra publish command required after installation.

Need to refresh the assets after making manual edits or upgrading? Re-run the publish command and pick the `module-generator` tag to overwrite the files.

```
php artisan vendor:publish --provider="Efati\ModuleGenerator\ModuleGeneratorServiceProvider" --tag=module-generator
```

To customise the stub templates used for every generated file, publish the dedicated stubs when you need them:

```
php artisan vendor:publish --provider="Efati\ModuleGenerator\ModuleGeneratorServiceProvider" --tag=module-generator-stubs
php artisan vendor:publish --provider="Efati\\ModuleGenerator\\ModuleGeneratorServiceProvider" --tag=module-generator-stubs
```

This copies the templates to `resources/stubs/module-generator`, letting you adapt method signatures, imports, or formatting to match your house style. Leave them unpublished if the defaults already suit your project.

Quick start
-----------

[](#quick-start)

### Basic API module with form requests and tests

[](#basic-api-module-with-form-requests-and-tests)

```
php artisan make:module Product -a --requests --tests
```

This generates:

- Repository interface + Eloquent implementation
- Service interface + implementation
- DTO class
- API controller with form requests
- API resource
- Feature tests

### With schema metadata from migration

[](#with-schema-metadata-from-migration)

```
php artisan make:module Product -a --from-migration=create_products_table
```

### With inline schema (no migration needed)

[](#with-inline-schema-no-migration-needed)

```
php artisan make:module Product -a \
  --fields="name:string:unique, price:decimal(10,2), is_active:boolean"
```

### With action layer

[](#with-action-layer)

```
php artisan make:module Product -a --actions
```

Generates invokable action classes for each CRUD operation (List, Show, Create, Update, Delete).

Command options
---------------

[](#command-options)

OptionAliasDescription`--api``-a`Generate API controller with form requests and actions. Automatically enables `--requests` and `--actions`.`--actions`–Generate invokable action classes for CRUD operations.`--requests``-r`Generate `Store` and `Update` form requests.`--tests``-t`Generate CRUD feature tests.`--controller=Subdir``-c`Place controller in a subfolder (e.g., `Admin`).`--swagger``-sg`Generate OpenAPI documentation in `App\Docs\{Module}Doc`.`--no-actions`–Skip action layer generation (opposite of `--actions`).`--all` / `--full``-a` / `-f`Generate complete stack: controllers, requests, resources, tests, provider, DTOs, swagger, actions.`--from-migration=``-fm`Infer schema from migration file name or path.`--fields=`–Inline schema: `name:string:unique, email:email, price:decimal(10,2)``--no-controller``-nc`Skip controller generation.`--no-resource``-nr`Skip API resource generation.`--no-dto``-nd`Skip DTO generation.`--no-test``-nt`Skip feature tests.`--no-provider``-np`Skip provider creation.`--no-swagger`–Disable Swagger generation.`--force``-f`Overwrite existing files.**Default behavior** can be configured in `config/module-generator.php` under the `defaults` section.

Schema inference
----------------

[](#schema-inference)

The generator builds accurate metadata from multiple sources:

- **Migration parsing** – Extract columns, types, nullability, uniqueness, and foreign keys from migration files
- **Inline schema** – Define fields directly: `name:string:unique, price:decimal(10,2), active:boolean`
- **Model inspection** – Fall back to fillable fields and relationships from your Eloquent model

This metadata feeds into DTOs, form requests, resources, and tests automatically.

Generated files
---------------

[](#generated-files)

Each module includes:

- **Repository** – Interface + Eloquent implementation with Criteria pattern support
- **Service** – Business logic layer with interface for dependency injection and dynamic method forwarding
- **DTO** – Data transfer object with type hints, validation, and request conversion helpers
- **Controller** – API or web controller with dependency injection and resource formatting
- **Resource** – API resource for consistent JSON responses with relationship eager loading
- **Form Requests** – Store and Update request classes with auto-generated validation rules
- **Policy** – Authorization policies with standard CRUD gates
- **Feature Tests** – CRUD tests with success/failure scenarios using inferred field metadata
- **Provider** – Auto-registered service provider for bindings and dependency injection setup
- **Actions** (optional) – Invokable action classes for clean CRUD operation encapsulation

Feature tests
-------------

[](#feature-tests)

Generate CRUD tests with `--tests`:

```
php artisan make:module Product -a --tests
```

Tests include:

- Success and failure scenarios for all CRUD operations
- Auto-generated payloads based on schema metadata
- Validation error assertions
- Foreign key relationship checks

OpenAPI/Swagger documentation
-----------------------------

[](#openapiswagger-documentation)

### ✨ New: Built-in Swagger without external dependencies!

[](#-new-built-in-swagger-without-external-dependencies)

Generate interactive API documentation with **zero external packages**:

```
# 1. Initialize Swagger UI
php artisan swagger:init

# 2. Generate documentation from routes
php artisan swagger:generate

# 3. View in browser
php artisan swagger:ui
# Visits: http://localhost:8000/docs
```

**Or integrate with your Laravel app:**

In `routes/api.php`:

```
use Efati\ModuleGenerator\Traits\RegistersSwaggerRoutes;

Route::middleware(['api'])->group(function () {
    Route::registerSwaggerRoutes(); // Adds /api/docs
    Route::apiResource('products', ProductController::class);
});
```

Visit: `http://localhost:8000/api/docs`

**Features:**

- ✅ No L5-Swagger or Swagger-PHP dependency
- ✅ Beautiful, responsive UI
- ✅ Automatic route scanning
- ✅ OpenAPI 3.0 compliant
- ✅ Fully customizable
- ✅ Production-ready

👉 [Full Swagger Documentation](SWAGGER_NO_DEPENDENCIES.md)

### PHPDoc Annotations (OpenAPI-compatible)

[](#phpdoc-annotations-openapi-compatible)

Generate PHPDoc documentation files with `@OA\` annotations:

```
# Add Swagger documentation to a module
php artisan make:module Product --swagger

# Or generate documentation for all routes
php artisan make:swagger --force
```

This creates PHPDoc files in `app/Docs/` that are **automatically compatible with optional packages** like `zircote/swagger-php` or `l5-swagger`:

```
