zakariadev000/laravel-crud-generator

Generate full CRUD (Model, Migration, Controller, Request, Resource, Repository, Service, Routes, Tests) with a single artisan command

Maintainers

Package info

github.com/ZakariaDev000/laravel-crud-generator

pkg:composer/zakariadev000/laravel-crud-generator

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-04-05 04:08 UTC

This package is auto-updated.

Last update: 2026-05-05 04:30:25 UTC


README

Laravel 12+ PHP 8.2+ License: MIT

Generate a complete CRUD stack (Model, Migration, Controller, FormRequest, Resource, Repository, Service, Routes, Tests, Factory, Seeder) with a single artisan command.

Installation

composer require zakariadev000/laravel-crud-generator --dev

Publish the config file:

php artisan vendor:publish --tag=crud-generator-config

Optionally publish stubs for customization:

php artisan vendor:publish --tag=crud-generator-stubs

Quick Start

php artisan make:full-crud Product --fields="name:string,price:decimal,description:text,category_id:foreignId,is_active:boolean"

This generates all 11 files in the right directories, ready to use.

Command Usage

# Generate everything with default fields
php artisan make:full-crud Product

# With field definitions
php artisan make:full-crud Product --fields="name:string,price:decimal,description:text,category_id:foreignId,is_active:boolean"

# Selective generation
php artisan make:full-crud Product --no-tests --no-repository
php artisan make:full-crud Product --only=model,migration,controller

# Options
php artisan make:full-crud Product --api           # API only (no views)
php artisan make:full-crud Product --soft-deletes   # Add soft deletes
php artisan make:full-crud Product --force          # Overwrite existing files

All Options

Option Description
--fields= Field definitions (name:type,name:type)
--api API-only mode
--soft-deletes Add SoftDeletes trait and migration column
--force Overwrite existing files
--no-tests Skip test generation
--no-repository Skip repository generation
--no-service Skip service generation
--no-factory Skip factory generation
--no-seeder Skip seeder generation
--no-routes Skip route generation
--only= Only generate specific components (comma-separated)

Supported Field Types

Type Migration Validation Faker
string string() required|string|max:255 Context-aware (name, email, etc.)
text text() required|string|max:65535 paragraph()
integer integer() required|integer numberBetween()
bigInteger bigInteger() required|integer numberBetween()
decimal decimal(10,2) required|numeric|min:0 randomFloat()
boolean boolean() sometimes|boolean boolean()
date date() required|date date()
datetime dateTime() required|date dateTime()
json json() required|array []
foreignId foreignId()->constrained() required|integer|exists:table,id Related factory

Generated Files

For php artisan make:full-crud Product:

app/
  Models/Product.php
  Http/
    Controllers/ProductController.php
    Requests/
      StoreProductRequest.php
      UpdateProductRequest.php
    Resources/
      ProductResource.php
      ProductCollection.php
  Repositories/ProductRepository.php
  Services/ProductService.php
database/
  migrations/xxxx_create_products_table.php
  factories/ProductFactory.php
  seeders/ProductSeeder.php
routes/api.php  (appended)
tests/Feature/ProductTest.php

Configuration

// config/crud-generator.php
return [
    'defaults' => [
        'model' => true,
        'migration' => true,
        'controller' => true,
        'form_request' => true,
        'api_resource' => true,
        'repository' => true,
        'service' => true,
        'routes' => true,
        'tests' => true,
        'factory' => true,
        'seeder' => true,
    ],
    'api_prefix' => 'api/v1',
    'namespace' => 'App',
    'pattern' => 'repository-service',
    'soft_deletes' => false,
    'timestamps' => true,
    'pagination' => 25,
];

Architecture

The generated code follows the Repository-Service pattern:

Controller -> Service -> Repository -> Model
  • Controller: Handles HTTP, delegates to Service
  • Service: Business logic, orchestration
  • Repository: Data access, queries, filtering
  • Model: Eloquent model with fillable, casts, relationships

Customizing Stubs

After publishing stubs, edit them in resources/stubs/vendor/crud-generator/. Available placeholders:

  • {{ namespace }} - App namespace
  • {{ model }} - Model class name
  • {{ variable }} - Camel case model name
  • {{ table }} - Snake case plural table name
  • {{ fillable }} - Fillable array
  • {{ casts }} - Casts array
  • {{ columns }} - Migration columns
  • {{ rules }} - Validation rules
  • {{ fields }} - Resource fields

Contributing

  1. Fork the repo
  2. Create a feature branch (git checkout -b feature/amazing)
  3. Commit your changes
  4. Push to the branch
  5. Open a Pull Request

License

MIT License. See LICENSE for details.