PHPackages                             fariddomat/auto-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. [API Development](/categories/api)
4. /
5. fariddomat/auto-generator

ActiveLibrary[API Development](/categories/api)

fariddomat/auto-generator
=========================

Automates CRUD and API generation for Laravel models.

05PHP

Since May 6Pushed 1y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

AutoGenerator Package for Laravel
=================================

[](#autogenerator-package-for-laravel)

The `Fariddomat\AutoGenerator` package is a powerful tool designed to streamline the creation of CRUD (Create, Read, Update, Delete) and API modules in Laravel applications. It provides an interactive command-line interface to generate models, migrations, controllers, views, routes, and OpenAPI specifications with minimal effort.

Features
========

[](#features)

- *Interactive CLI* to define models, fields, and settings.
- Generates **CRUD controllers**, Blade views, and routes for web applications.
- Generates **API controllers**, routes, and OpenAPI specs for RESTful APIs.
- Supports relationships (*select* for `belongsTo`, *belongsToMany*).
- Optional features: **soft deletes**, *search functionality*, middleware, and dashboard prefix.
- Validation rules generated in models.
- File handling for uploads (files, images, multiple images).

Requirements
============

[](#requirements)

- PHP &gt;= 8.1
- Laravel &gt;= 9.x
- Composer

Installation
============

[](#installation)

Install the package via Composer:

```
composer require fariddomat/auto-generator:dev-main
```

### Publish Configuration (Optional)

[](#publish-configuration-optional)

If the package includes a configuration file, publish it:

```
php artisan vendor:publish --provider="Fariddomat\AutoGenerator\AutoGeneratorServiceProvider"
```

*Note:* If no service provider exists yet, you’ll need to register it manually in `config/app.php`:

```
'providers' => [
    // ...
    Fariddomat\AutoGenerator\AutoGeneratorServiceProvider::class,
],
```

Usage
=====

[](#usage)

Run the interactive generator command:

```
php artisan make:auto
```

### Interactive Prompts

[](#interactive-prompts)

- **Model Name**: Enter the model name (e.g., `Post`, must start with a capital letter).
- **Fields**: Define fields (e.g., `title:string`, `user_id:select`, `roles:belongsToMany`). Leave blank to finish.
    - *Supported types*: `string`, `text`, `integer`, `decimal`, `boolean`, `select`, `belongsToMany`, `file`, `image`, `images`, `enum`, `date`, `datetime`, `json`.
    - *Modifiers*: `nullable`, `unique` (e.g., `title:string:nullable`).
- **Type**: Choose `crud`, `api`, or `both`.
- **API Version**: Specify version (e.g., `v1`) if API is selected.
- **Dashboard Prefix**: Use `dashboard.` prefix for views and routes (yes/no).
- **Soft Deletes**: Enable soft deletes (yes/no).
- **Search**: Enable search for API (yes/no), with optional searchable fields.
- **Middleware**: Add middleware (e.g., `auth:api,throttle`).

### Example Command

[](#example-command)

Generate a `Post` model with CRUD and API:

```
php artisan make:auto
Post
title:string
user_id:select
images:images:nullable
2
v1
yes
yes
yes
auth:api
```

### Generated Output

[](#generated-output)

- *Model*: `app/Models/Post.php` with `$fillable`, rules, relationships, and optional `$searchable`.
- *Migration*: `database/migrations/*_create_posts_table.php`.
- *CRUD Controller*: `app/Http/Controllers/Dashboard/PostController.php`.
- *Views*: `resources/views/dashboard/posts/{index,create,edit,show}.blade.php`.
- *API Controller*: `app/Http/Controllers/PostApiController.php`.
- *Routes*: Added to `routes/web.php` (CRUD) and `routes/api.php` (API).
- *OpenAPI Spec*: `openapi/Post.json`.

For `belongsToMany` (e.g., `roles:belongsToMany`):

- *Pivot table migration* (e.g., `post_roles`).
- *Relationship method* in the model (e.g., `public function roles()`).

Example Generated Model
=======================

[](#example-generated-model)

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Post extends Model
{
    use SoftDeletes;

    protected $fillable = ['title', 'user_id', 'images'];

    public static function rules()
    {
        return [
            'title' => 'required|string|max:255',
            'user_id' => 'required|exists:users,id',
            'images' => 'nullable|array',
            'images.*' => 'image|mimes:jpeg,png,jpg,gif|max:2048',
        ];
    }

    protected $searchable = ['title'];

    public function user()
    {
        return $this->belongsTo(\App\Models\User::class, 'user_id');
    }
}
```

Notes on Relationships
======================

[](#notes-on-relationships)

- *`select`*: Generates a `belongsTo` relationship (e.g., `user_id:select` → `belongsTo(User)`).
- *`belongsToMany`*: Generates a many-to-many relationship with a pivot table (e.g., `users:belongsToMany` → `belongsToMany(User, 'gara_user')`).
    - *Ensure* the related model (e.g., `User`) exists before migrating.

Post-Generation Steps
=====================

[](#post-generation-steps)

- **Run Migrations**: ```
    php artisan migrate
    ```
- **Test Routes**:
    - *CRUD*: Visit `/dashboard/posts` (if dashboard enabled).
    - *API*: Test `/api/v1/posts` with a tool like Postman.

Customization
=============

[](#customization)

- *Edit Generated Files*: Modify controllers, views, or migrations as needed.
- *Extend the Generator*: Update `src/Services/*Generator.php` files to add custom logic.

Troubleshooting
===============

[](#troubleshooting)

- *Class Not Found*: Ensure related models (e.g., `User`) exist. Generate them with `php artisan make:model User -m` if missing.
- *Pivot Table Errors*: Verify pivot table names match the model’s relationship definition (e.g., `gara_user` vs. `gara_users`).
- *Validation Issues*: Check `rules()` in the model for correct syntax.

Contributing
============

[](#contributing)

Feel free to fork the repository, submit pull requests, or report issues on [GitHub](https://github.com/fariddomat/auto-generator).

License
=======

[](#license)

This package is open-source software licensed under the [MIT License](https://opensource.org/licenses/MIT).

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity15

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/67d09c13658910630a603e0e8e6937e392d6ab5ee8f6d5450a2b4d1b56768a03?d=identicon)[fariddomat](/maintainers/fariddomat)

---

Top Contributors

[![farid-domat](https://avatars.githubusercontent.com/u/239963924?v=4)](https://github.com/farid-domat "farid-domat (11 commits)")

### Embed Badge

![Health badge](/badges/fariddomat-auto-generator/health.svg)

```
[![Health](https://phpackages.com/badges/fariddomat-auto-generator/health.svg)](https://phpackages.com/packages/fariddomat-auto-generator)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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