PHPackages                             votapil/votacrudgenerator - 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. [Database &amp; ORM](/categories/database)
4. /
5. votapil/votacrudgenerator

ActiveLibrary[Database &amp; ORM](/categories/database)

votapil/votacrudgenerator
=========================

Generate CRUD from your databases

045PHPCI passing

Since Feb 27Pushed 2mo agoCompare

[ Source](https://github.com/votapil/VotaCrudGenerator)[ Packagist](https://packagist.org/packages/votapil/votacrudgenerator)[ RSS](/packages/votapil-votacrudgenerator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

VotaCrudGenerator
=================

[](#votacrudgenerator)

[![Latest Version on Packagist](https://camo.githubusercontent.com/aca946d4e379551e5b7d8b9bf16da7cfd1668320fce3057266d6e1e43f3e2796/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f766f746170696c2f766f74616372756467656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/votapil/votacrudgenerator)[![Total Downloads](https://camo.githubusercontent.com/4b7ad02ca9c8bb659ffe82d696d052fb0ec00505fd31fd4ac6a3594f9972ead2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f766f746170696c2f766f74616372756467656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/votapil/votacrudgenerator)

**Generate production-ready CRUD scaffolding from your existing database tables** for Laravel 11 &amp; 12. Introspects your DB schema and generates Models, API Controllers, FormRequests, Resources, Policies, and Factories — all following modern Laravel best practices.

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

[](#installation)

```
composer require votapil/votacrudgenerator --dev
```

Publish the config (optional):

```
php artisan vendor:publish --tag="votacrudgenerator-config"
```

Quick Start
-----------

[](#quick-start)

```
# Generate full CRUD for the "posts" table
php artisan vota:crud Post
```

This creates:

- `app/Models/Post.php` — with fillable, casts, SoftDeletes, relationships
- `app/Http/Controllers/PostController.php` — API controller
- `app/Http/Requests/PostStoreRequest.php` — validation from DB types
- `app/Http/Requests/PostUpdateRequest.php` — partial update rules
- `app/Http/Resources/PostResource.php` — JSON resource
- `app/Policies/PostPolicy.php` — authorization
- `database/factories/PostFactory.php` — smart faker
- Route added to `routes/api.php`

> **Note:** Laravel 11+ does not include `routes/api.php` by default. Run `php artisan install:api` first to enable API routing, then use the generator.

Usage
-----

[](#usage)

```
php artisan vota:crud {ModelName} [options]
```

Model name should be **singular PascalCase**. Table name is derived automatically (`Post` → `posts`, `BlogPost` → `blog_posts`).

### Options

[](#options)

OptionDescriptionExample`--path=`Sub-path for namespace grouping`--path=Blog` → `App\Models\Blog\Post``--namespace=`Override base model namespace`--namespace="App\Models\Admin"``--table=`Explicit table name (skip convention)`--table=wp_posts``--no-policy`Skip Policy generation`--no-request`Skip FormRequest generation`--no-resource`Skip Resource generation`--no-factory`Skip Factory generation`--no-route`Skip route injection`--force`Overwrite existing files### Examples

[](#examples)

```
# Grouped namespace
php artisan vota:crud Post --path=Blog

# Custom namespace
php artisan vota:crud Post --namespace="App\Models\Admin"

# Non-standard table name
php artisan vota:crud Post --table=legacy_blog_posts

# Only Model + Controller
php artisan vota:crud Post --no-policy --no-request --no-resource --no-factory --no-route

# Regenerate (overwrite)
php artisan vota:crud Post --force
```

### Customize Stubs

[](#customize-stubs)

```
php artisan vota:stubs
```

Publishes stubs to `stubs/vendor/votacrud/` for editing. The generator uses your custom stubs when available.

---

Why This Approach?
------------------

[](#why-this-approach)

### Database-First Development

[](#database-first-development)

Most CRUD generators work top-down: define fields in config, generate migrations. **VotaCrudGenerator works bottom-up**: your database is the single source of truth.

This is powerful when:

- Working with an **existing database** (legacy systems, shared DBs, DBA-designed schemas)
- Preferring **migrations-first** workflow — scaffold *after* the schema is ready
- Onboarding onto a project — quickly scaffold models for dozens of tables

### Smart Schema Analysis

[](#smart-schema-analysis)

The generator doesn't just read column names — it understands your schema:

DetectionWhat Happens`deleted_at` columnAdds `SoftDeletes` trait + `restore()` / `forceDelete()` endpointsForeign key constraintsAuto-generates `belongsTo()` and `hasMany()` relationshipsColumn typesMaps to `$casts`, validation rules, and Faker methodsUnique indexesAdds `unique` validation ruleNullable columns`nullable` instead of `required` in validationColumn names (email, phone…)Picks appropriate Faker methods### Advantages Over Manual Scaffolding

[](#advantages-over-manual-scaffolding)

- **Zero typos** — field names, types, relationships come directly from the DB
- **Consistency** — every generated file follows the same conventions
- **Speed** — scaffold a complete CRUD in seconds
- **Best Practices** — typed returns, `validated()` over `$request->all()`, proper HTTP status codes
- **Customizable** — publish and modify stubs to match your project style

---

Generated Files in Detail
-------------------------

[](#generated-files-in-detail)

### Model

[](#model)

- `$fillable` from non-system columns
- `casts()` method from column types (json → `array`, bool → `boolean`, etc.)
- `SoftDeletes` trait when `deleted_at` detected
- `belongsTo()` / `hasMany()` from foreign keys
- `HasFactory` trait included

### Controller (API)

[](#controller-api)

- RESTful: `index`, `store`, `show`, `update`, `destroy`
- Uses `$request->validated()` for security
- Proper HTTP status codes (`201` create, `204` delete)
- Eager loading via `?with=relation1,relation2`
- SoftDeletes: adds `restore()` and `forceDestroy()`

### FormRequests

[](#formrequests)

- **Store**: rules mapped from DB types (`integer`, `string|max:255`, `nullable`, `date`)
- **Update**: same with `sometimes` prefix for partial updates
- Unique constraints from DB indexes included

### Resource

[](#resource)

- All columns mapped, `JsonResource` with typed `toArray(Request $request): array`

### Policy

[](#policy)

- Standard methods: `viewAny`, `view`, `create`, `update`, `delete`
- `restore` / `forceDelete` when SoftDeletes detected
- `App\Models\User`, no deprecated `HandlesAuthorization` trait
- Auto-discovered by Laravel 11/12

### Factory

[](#factory)

- Faker by column name (`email` → `safeEmail()`, `name` → `name()`)
- Falls back to type-based (`integer` → `randomNumber()`)

### Routes

[](#routes)

Auto-appends to `routes/api.php`:

```
Route::apiResource('posts', \App\Http\Controllers\PostController::class);
// + restore/forceDestroy routes when SoftDeletes detected
```

> **Note:** Laravel 11+ requires `php artisan install:api` before `routes/api.php` exists. If the file is missing, the generator prints the route snippet to the console instead of failing.

---

Customization Guide
-------------------

[](#customization-guide)

### Stub Placeholders

[](#stub-placeholders)

**Simple placeholders:**

```
{{ modelName }}        → Post
{{ modelVariable }}    → post
{{ modelNamespace }}   → App\Models
{{ fillable }}         → ['title', 'body', ...]
{{ validationRules }}  → ['title' => 'required|string|max:255', ...]

```

**Conditional blocks:**

```
{{#if softDeletes}}
use Illuminate\Database\Eloquent\SoftDeletes;
{{/if softDeletes}}

```

### Configuration

[](#configuration)

All defaults in `config/votacrudgenerator.php`:

```
return [
    'namespaces' => [
        'model'      => 'App\\Models',
        'controller' => 'App\\Http\\Controllers',
        'request'    => 'App\\Http\\Requests',
        'resource'   => 'App\\Http\\Resources',
        'policy'     => 'App\\Policies',
    ],
    'generate' => [
        'model' => true, 'controller' => true,
        'store_request' => true, 'update_request' => true,
        'resource' => true, 'policy' => true,
        'factory' => true, 'routes' => true,
    ],
    'detect' => [
        'soft_deletes' => true, 'timestamps' => true,
        'relationships' => true, 'casts' => true,
    ],
    'route_file'   => 'routes/api.php',
    'route_prefix' => '',
    'packages' => [
        'spatie_query_builder' => false,
    ],
];
```

### Extending the Generator

[](#extending-the-generator)

- **Custom validation rules**: Override `getColumnValidationRule()` in a custom `DatabaseIntrospector` bound via the service container
- **Custom faker methods**: Override `getColumnFaker()` for project-specific patterns
- **New file types**: Create a stub in `stubs/vendor/votacrud/` and extend `CrudGenerateCommand`

---

🤖 AI Skills / Cursor Rules
--------------------------

[](#-ai-skills--cursor-rules)

If you use AI coding assistants like **Cursor**, **GitHub Copilot**, or **Antigravity**, you can train them to use `VotaCrudGenerator` instead of writing manual, error-prone CRUD boilerplate.

Because the generator extracts your **Database Column Comments** into Model PHPDocs and Resource fields, your AI will instantly understand the business context of every auto-generated field.

Add the following block to your project's `.cursorrules`, GitHub Copilot instructions, or AI agent context (e.g., `skills/votacrud.md`):

```
# Laravel CRUD Generation

When asked to create a new CRUD, resource, or model with its related files:
1. DO NOT write the Model, Controller, Requests, Resource, Policy, or Factory manually.
2. Ask the user to create and run the database migration first. Ensure you add `->comment(...)` to the columns to provide business context.
3. Once the database table is ready, use the VotaCrudGenerator package by running:
   `php artisan vota:crud {ModelName}`
4. The package will automatically introspect the database and generate all necessary files based on the concrete table schema (columns, types, foreign keys, soft deletes, and comments).
5. Only make manual edits to the generated files if specific custom business logic is requested.
```

---

Multi-Database Support
----------------------

[](#multi-database-support)

Works with any Laravel-supported driver via the `Schema` facade:

DatabaseColumnsForeign KeysIndexesMySQL✅✅✅PostgreSQL✅✅✅SQLite✅✅✅Requirements
------------

[](#requirements)

- PHP 8.3+
- Laravel 11.x or 12.x
- Existing database with tables

License
-------

[](#license)

MIT — see [LICENSE.md](LICENSE.md)

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance57

Moderate activity, may be stable

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity14

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/6999c8dae343864716cb8b1f3321b85943d038879717295e2f089b2032da74c6?d=identicon)[votapil](/maintainers/votapil)

---

Top Contributors

[![votapil](https://avatars.githubusercontent.com/u/808252?v=4)](https://github.com/votapil "votapil (12 commits)")

### Embed Badge

![Health badge](/badges/votapil-votacrudgenerator/health.svg)

```
[![Health](https://phpackages.com/badges/votapil-votacrudgenerator/health.svg)](https://phpackages.com/packages/votapil-votacrudgenerator)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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