PHPackages                             yassin-ahmed/laravel-api-crud-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. yassin-ahmed/laravel-api-crud-generator

ActiveLibrary[API Development](/categories/api)

yassin-ahmed/laravel-api-crud-generator
=======================================

A comprehensive CRUD generator for Laravel API development

v1.0.1(10mo ago)039MITPHPPHP ^8.1|^8.2|^8.3

Since Jun 19Pushed 10mo agoCompare

[ Source](https://github.com/Yassin3007/laravel-api-crud-generator)[ Packagist](https://packagist.org/packages/yassin-ahmed/laravel-api-crud-generator)[ RSS](/packages/yassin-ahmed-laravel-api-crud-generator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

Laravel API CRUD Generator
==========================

[](#laravel-api-crud-generator)

A powerful Laravel package that generates complete CRUD APIs with a single command. This package creates everything you need for a fully functional REST API including models, controllers, requests, resources, migrations, factories, seeders, tests, and routes.

🚀 Features
----------

[](#-features)

- **Complete CRUD Generation**: Models, Controllers, Requests, Resources, Migrations, Factories, Seeders, Tests, and Routes
- **Field Type Support**: String, text, integer, boolean, date, email, JSON, decimal, float, and more
- **Relationship Support**: BelongsTo and HasMany relationships
- **Validation**: Automatic validation rules generation based on field types
- **API Resources**: JSON API responses with proper formatting
- **Pagination**: Built-in pagination support with meta information
- **Search &amp; Filtering**: Search functionality and sorting options
- **Factory &amp; Seeders**: Automatic fake data generation for testing
- **Feature Tests**: Complete test suite for all CRUD operations
- **Smart Fake Data**: Context-aware fake data generation (emails, names, phones, etc.)

📦 Installation
--------------

[](#-installation)

Install the package via Composer:

```
composer require yassin-ahmed/laravel-api-crud-generator
```

Publish the package configuration (optional):

```
php artisan vendor:publish --provider="Yassin\LaravelApiCrudGenerator\ServiceProvider"
```

🎯 Quick Start
-------------

[](#-quick-start)

Generate a complete CRUD API with a single command:

```
php artisan crud:generate Post --fields="title:string,content:text,published:boolean,published_at:date:nullable"
```

This creates:

- Migration file
- Post model
- PostController (API)
- Store/Update request classes
- PostResource
- API routes
- PostFactory
- PostSeeder
- Feature tests

📝 Usage
-------

[](#-usage)

### Basic Usage

[](#basic-usage)

```
# Simple model with basic fields
php artisan crud:generate Product --fields="name:string,price:decimal,description:text"

# With nullable fields
php artisan crud:generate User --fields="name:string,email:email,phone:string:nullable,bio:text:nullable"

# With relationships
php artisan crud:generate Post --fields="title:string,content:text" --relations="belongsTo:User,hasMany:Comment"
```

### Command Options

[](#command-options)

OptionDescriptionExample`--fields`Define model fields with types`--fields="name:string,age:integer"``--relations`Define model relationships`--relations="belongsTo:User,hasMany:Post"``--force`Overwrite existing files`--force`### Field Types

[](#field-types)

TypeDescriptionValidation Rule`string`Short text (255 chars)`string|max:255``text`Long text`string``integer`Whole numbers`integer``boolean`True/false values`boolean``date`Date values`date``email`Email addresses`email``json`JSON data`json``decimal`Decimal numbers`numeric``float`Floating point numbers`numeric`### Relationship Types

[](#relationship-types)

TypeDescriptionExample`belongsTo`Many-to-one relationship`belongsTo:User``hasMany`One-to-many relationship`hasMany:Comment`📚 Examples
----------

[](#-examples)

### E-commerce Product

[](#e-commerce-product)

```
php artisan crud:generate Product \
  --fields="name:string,description:text,price:decimal,stock:integer,is_active:boolean,category_id:integer" \
  --relations="belongsTo:Category,hasMany:OrderItem"
```

### Blog System

[](#blog-system)

```
# Create Category
php artisan crud:generate Category --fields="name:string,slug:string,description:text:nullable"

# Create Post with relationship
php artisan crud:generate Post \
  --fields="title:string,slug:string,content:text,excerpt:text:nullable,published_at:date:nullable,is_published:boolean" \
  --relations="belongsTo:User,belongsTo:Category,hasMany:Comment"

# Create Comment
php artisan crud:generate Comment \
  --fields="content:text,author_name:string,author_email:email" \
  --relations="belongsTo:Post"
```

### User Management

[](#user-management)

```
php artisan crud:generate Profile \
  --fields="first_name:string,last_name:string,bio:text:nullable,avatar:string:nullable,phone:string:nullable,date_of_birth:date:nullable" \
  --relations="belongsTo:User"
```

🔧 Generated Files Structure
---------------------------

[](#-generated-files-structure)

After running the command, the following files are created:

```
app/
├── Models/
│   └── YourModel.php
├── Http/
│   ├── Controllers/Api/
│   │   └── YourModelController.php
│   ├── Requests/YourModel/
│   │   ├── StoreYourModelRequest.php
│   │   └── UpdateYourModelRequest.php
│   └── Resources/
│       └── YourModelResource.php
database/
├── migrations/
│   └── xxxx_xx_xx_xxxxxx_create_your_models_table.php
├── factories/
│   └── YourModelFactory.php
└── seeders/
    └── YourModelSeeder.php
routes/api/
└── YourModel.php
tests/Feature/YourModel/
└── YourModelApiTest.php

```

🌐 API Endpoints
---------------

[](#-api-endpoints)

The generated controller provides these endpoints:

MethodEndpointDescription`GET``/api/your-models`List all records (with pagination)`POST``/api/your-models`Create new record`GET``/api/your-models/{id}`Show specific record`PUT/PATCH``/api/your-models/{id}`Update record`DELETE``/api/your-models/{id}`Delete record### Query Parameters

[](#query-parameters)

- `search` - Search in name field
- `sort_by` - Field to sort by
- `sort_direction` - Sort direction (asc/desc)
- `per_page` - Records per page (default: 15)

### Example API Calls

[](#example-api-calls)

```
# List products with pagination
GET /api/products?per_page=10&page=1

# Search products
GET /api/products?search=laptop

# Sort products by price
GET /api/products?sort_by=price&sort_direction=desc

# Create product
POST /api/products
{
    "name": "Laptop",
    "price": 999.99,
    "description": "High-performance laptop"
}

# Update product
PUT /api/products/1
{
    "name": "Gaming Laptop",
    "price": 1299.99
}
```

🧪 Testing
---------

[](#-testing)

The package generates comprehensive feature tests. Run them with:

```
# Run all tests
php artisan test

# Run specific model tests
php artisan test tests/Feature/Product/ProductApiTest.php

# Run with coverage
php artisan test --coverage
```

🔄 After Generation
------------------

[](#-after-generation)

1. **Run migrations**:

    ```
    php artisan migrate
    ```
2. **Register routes** (if not using automatic discovery):

    ```
    // In routes/api.php
    require_once __DIR__ . '/api/Product.php';
    ```
3. **Run seeders** (optional):

    ```
    php artisan db:seed --class=ProductSeeder
    ```
4. **Customize as needed**:

    - Update validation rules in request classes
    - Modify API resource fields
    - Add custom methods to controllers
    - Enhance factory definitions

⚡ Advanced Features
-------------------

[](#-advanced-features)

### Custom Validation

[](#custom-validation)

Update the generated request classes to add custom validation:

```
// In StoreProductRequest.php
public function rules()
{
    return [
        'name' => 'required|string|max:255|unique:products',
        'price' => 'required|numeric|min:0',
        'description' => 'nullable|string|max:1000',
    ];
}
```

### Custom API Resources

[](#custom-api-resources)

Enhance the generated resource classes:

```
// In ProductResource.php
public function toArray($request)
{
    return [
        'id' => $this->id,
        'name' => $this->name,
        'price' => number_format($this->price, 2),
        'description' => $this->description,
        'formatted_price' => '$' . number_format($this->price, 2),
        'category' => new CategoryResource($this->whenLoaded('category')),
        'created_at' => $this->created_at->format('Y-m-d H:i:s'),
        'updated_at' => $this->updated_at->format('Y-m-d H:i:s'),
    ];
}
```

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License
---------

[](#-license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

📞 Support
---------

[](#-support)

If you encounter any issues or have questions:

1. Check the [issues page](https://github.com/yassin/laravel-api-crud-generator/issues)
2. Create a new issue if your problem isn't already reported
3. Provide detailed information about your Laravel version and the command you used

🙏 Credits
---------

[](#-credits)

Created by [Yassin](https://github.com/Yassin3007)

---

Made with ❤️ for the Laravel community

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance53

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

328d ago

PHP version history (2 changes)v1.0.0PHP ^8.1

v1.0.1PHP ^8.1|^8.2|^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/a5d406af1aafdc5e2409a21174a2b91f77bc67c985c6fb7e849ee9238d656a08?d=identicon)[Yassin3007](/maintainers/Yassin3007)

---

Top Contributors

[![Yassin3007](https://avatars.githubusercontent.com/u/103891306?v=4)](https://github.com/Yassin3007 "Yassin3007 (8 commits)")

---

Tags

apilaravelgeneratorartisancrud

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/yassin-ahmed-laravel-api-crud-generator/health.svg)

```
[![Health](https://phpackages.com/badges/yassin-ahmed-laravel-api-crud-generator/health.svg)](https://phpackages.com/packages/yassin-ahmed-laravel-api-crud-generator)
```

PHPackages © 2026

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