tgozo / laravel-codegen
A Laravel Code Generator to help you get started with a lot of staff including generating Migrations, Models, Controllers, Factories, Routes, Views, Database Seeders and Request Validation Rules.
Requires
- doctrine/inflector: ^2.0
- laravel/prompts: ^0.1
Requires (Dev)
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Stop writing boilerplate code. Start building features.
Laravel CodeGen is a production-grade code generation suite that transforms your development workflow by automatically scaffolding complete, tested, production-ready Laravel components with terminal prompts, interactive wizards, modern frontend templates (Vue 3, React TSX, Inertia, Blade, Livewire), and domain-driven design support.
โจ Key Capabilities
- ๐โโ๏ธ 10x Faster Scaffolding: Scaffolds complete CRUD modules in seconds with zero configuration.
- ๐ช Interactive Scaffolding Wizard: Run
php artisan codegen:wizardfor interactive prompt-guided generation. - ๐จ Modern Frontend Support: Built-in support for Inertia.js Vue 3, Inertia.js React (TSX), Blade, Livewire, and TypeScript definitions.
- ๐ฐ Domain-Driven Design (DDD): Use
--domain=DomainNameto structure modules cleanly into domain namespaces. - ๐ Form Requests & Backed Enums: Auto-infer validation rules (
--requests) and scaffold PHP 8.1+ String Enums (--enum). - ๐ก๏ธ Repository Pattern: Scaffold decoupled repository interfaces and Eloquent implementations (
--repository). - โก Domain Events & Listeners: Scaffold model lifecycle events and listener classes (
--events). - ๐ OpenAPI 3.0 Spec Generator: Generate
openapi.jsonspecs automatically (php artisan codegen:openapi). - ๐ Reverse Engineering Magic: Convert existing database tables into models, migrations, and controllers (
php artisan codegen:reverse-engineer). - ๐งน Cleanup & Rollback: Safely remove all generated module artifacts with
php artisan codegen:clean {Model}. - ๐ Publishable Stubs: Customize generated code templates using
php artisan codegen:publish-stubs. - ๐งช Pest PHP Test Suite: Auto-generates comprehensive Pest PHP feature tests out of the box.
๐ฆ Installation
Install via Composer:
composer require tgozo/laravel-codegen --dev
The package auto-registers its service provider. No extra setup required!
Optional: Publish Configuration & Custom Stubs
# Publish config file php artisan vendor:publish --tag="laravelcodegen-config" # Publish customizable stubs to resources/stubs/vendor/laravelcodegen php artisan codegen:publish-stubs
๐ Quick Start & CLI Usage
๐งโโ๏ธ Interactive Terminal Wizard
Run the interactive wizard powered by Laravel Prompts:
php artisan codegen:wizard
โก Scaffolding Command Flags
# Complete CRUD module with Vue 3 Inertia, Form Requests, and Pest Tests php artisan make:codegen-migration create_articles_table --all --inertia --requests -p # Complete DDD module with React TSX, TypeScript definitions, and Enums php artisan make:codegen-migration create_products_table --all --react --types --enum=ProductStatus:draft,published --domain=Catalog # Dry Run / Preview mode (simulates generation without creating files) php artisan make:codegen-migration create_orders_table --all --dry-run
Command Flag Reference
| Option | Description |
|---|---|
-m, --model |
Generate Eloquent Model with casts() and relationships |
-c, --controller |
Generate RESTful Controller |
-f, --factory |
Generate Model Factory with smart faker matching |
-s, --seeder |
Generate Database Seeder |
-p, --pest |
Generate Pest PHP feature test suite |
-l, --livewire |
Generate Livewire components |
--inertia |
Generate Vue 3 Inertia pages (Index.vue, Create.vue) |
--react |
Generate React TSX Inertia pages (Index.tsx, Create.tsx) |
--types |
Generate TypeScript definition (resources/js/types/{Model}.d.ts) |
--requests |
Generate Store{Model}Request.php & Update{Model}Request.php |
--enum=Name:case1,case2 |
Generate PHP 8.1+ Backed String Enum |
--repository |
Generate Repository contract and Eloquent implementation |
--events |
Generate App\Events\{Model}Created.php and Handle{Model}Created.php |
--soft-deletes-actions |
Include restore() and forceDelete() controller methods |
--domain=Name |
Scope generated files to domain path (DDD) |
--dry-run |
Preview generated files without writing to disk |
--all |
Generate complete module suite |
--force |
Overwrite existing files |
๐ ๏ธ Specialized Commands
๐ Reverse Engineer Existing Database
Convert an existing database table or schema into models and migrations:
# Reverse engineer all database tables php artisan codegen:reverse-engineer --all # Target specific tables php artisan codegen:reverse-engineer --tables=users,orders --all
๐ OpenAPI 3.0 Spec Generator
Generate OpenAPI 3.0 JSON specification for frontend clients and Postman:
php artisan codegen:openapi --output=openapi.json
๐งน Module Rollback & Cleanup
Safely inspect and delete all generated files for a specific module:
php artisan codegen:clean Article
๐ฆ Migration Squashing & Combining
Merge multiple incremental migrations into a single clean base migration file:
# Squash migrations for a single table php artisan make:codegen-squash products # Combine modifier migrations php artisan codegen:combine-migrations --table=users
๐งช Running Package Tests
The package features a complete Pest PHP test suite built on Orchestra Testbench:
cd the-package
./vendor/bin/pest tests
๐ Roadmap & Completed Features
- API Documentation - Auto-generate OpenAPI/Swagger 3.0 spec (
codegen:openapi) - Event/Listener System - Auto-generate domain events and listeners (
--events) - TypeScript Integration - Auto-generate TypeScript interface definitions (
--types) - React & Vue Support - Auto-generate Inertia Vue 3 & React TSX pages (
--inertia,--react) - Repository Pattern - Auto-generate repository contracts & Eloquent implementations (
--repository) - Interactive Terminal Wizard - Laravel Prompts guided workflow (
codegen:wizard) - Custom Stubs Loader - Publish & customize package stubs (
codegen:publish-stubs) - Docker Integration - Scaffolding custom Docker configurations
- Multi-tenancy Support - Scaffolding tenant-aware models and migrations
๐ก๏ธ Security
If you discover any security-related issues, please email dev@tgozo.co.zw instead of using the issue tracker.
๐ License
The MIT License (MIT). Please see License File for more information.
๐ Credits
- Takudzwa Gozo - GitHub
- All Contributors - Thank you for making this package better!
โญ If this package saved you time, please consider giving it a star on GitHub! โญ