PHPackages                             rahulp/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. rahulp/crud-generator

ActiveLibrary

rahulp/crud-generator
=====================

A Laravel package for generating CRUD operations with Repository Pattern

v1.0.3(1y ago)04MITPHPPHP ^8.2

Since Jan 18Pushed 1y ago1 watchersCompare

[ Source](https://github.com/rahulpathak1706/package-rahulp)[ Packagist](https://packagist.org/packages/rahulp/crud-generator)[ RSS](/packages/rahulp-crud-generator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

Laravel CRUD Generator with Repository Pattern
==============================================

[](#laravel-crud-generator-with-repository-pattern)

[![Latest Version on Packagist](https://camo.githubusercontent.com/91892b1ed3d503bebdc9df1c95fd9ff03d718b8095f301bbc85d87084fb8a50a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726168756c702f637275642d67656e657261746f722e737667)](https://packagist.org/packages/rahulp/crud-generator)[![License](https://camo.githubusercontent.com/59162da2a764b017f66dbd99af660f9d3421b260b8cc0a909c57b0a7a9d65b96/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f726168756c702f637275642d67656e657261746f722e737667)](https://github.com/rahulpathak1706/package-rahulp/blob/main/LICENSE)

A powerful Laravel package that generates complete CRUD operations with Repository Pattern implementation, along with API response helpers and database transaction middleware.

Features
--------

[](#features)

- 🚀 Project setup with essential middleware and helpers
- 🏗️ Generates Models, Controllers, Services, and Repositories
- 📦 Automatic repository binding setup
- 🔄 Database transaction middleware
- 📬 API response helper functions
- ⚡ Support for Laravel 11
- 🛠️ Customizable validation rules

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

[](#installation)

You can install the package via composer:

```
composer require rahulp/crud-generator
```

Commands
--------

[](#commands)

### 1. Project Setup (Required First)

[](#1-project-setup-required-first)

```
php artisan project:setup
```

This command sets up essential components needed for the CRUD operations:

#### A. Database Transaction Middleware

[](#a-database-transaction-middleware)

Automatically adds and registers middleware that:

- Wraps all API requests in database transactions
- Automatically commits on successful responses
- Rolls back on exceptions or error responses (4xx, 5xx)
- Handles exceptions gracefully

#### B. API Response Helpers

[](#b-api-response-helpers)

Adds global helper functions for consistent API responses:

1. Success Response Helper:

```
ok($message = null, $data = [], $status = 200);

// Examples:
return ok('User profile fetched', $user);
return ok('Post created', $post, 201);
```

Success Response Format:

```
{
    "meta": {
        "status": 200,
        "message": "User profile fetched",
        "success": true
    },
    "data": {
        "id": 1,
        "name": "John Doe",
        "email": "john@example.com"
    }
}
```

2. Error Response Helper:

```
error($message = null, $data = [], $type = null);

// Examples:
return error('Validation failed', $validator->errors(), 'validation');
return error('Post not found', [], 'notfound');
return error('Unauthorized access', [], 'forbidden');
```

Error Types and Status Codes:

- `validation` (422) - Validation errors
- `unauthenticated` (401) - Authentication required
- `notfound` (404) - Resource not found
- `forbidden` (403) - Permission denied
- `processError` (400) - Bad request
- `loginCase` (306) - Login specific errors
- Default (500) - Server errors

Error Response Format:

```
{
    "meta": {
        "status": 422,
        "message": "Validation failed",
        "success": false
    },
    "data": {
        "email": ["The email field is required"],
        "name": ["The name field is required"]
    }
}
```

### 2. Generate CRUD Operations

[](#2-generate-crud-operations)

After setting up the project, you can generate CRUD operations:

```
php artisan make:crud {model} {columns}
```

Parameters:

- `model`: Name of the model (e.g., Post, User, Product)
- `columns`: Column definitions in format: name:type:required|nullable:default

Supported Column Types:

- `string` - String/varchar fields
- `integer` - Whole numbers
- `decimal` - Decimal numbers (prices, measurements)
- `text` - Long text content
- `boolean` - True/false values
- `date` - Date only
- `datetime` - Date and time
- `timestamp` - Timestamps

Examples:

1. Basic Post Model:

```
php artisan make:crud Post title:string:required content:text:nullable
```

2. Product with Default Values:

```
php artisan make:crud Product \
    name:string:required \
    price:decimal:required:0.00 \
    description:text:nullable \
    stock:integer:required:0 \
    is_active:boolean:required:true
```

3. User Model with Validation:

```
php artisan make:crud User \
    name:string:required \
    email:string:required:unique \
    phone:string:nullable \
    status:string:required:active
```

Each `make:crud` command generates:

1. Database migration
2. Model with fillable fields and defaults
3. Repository interface and implementation
4. Service class for business logic
5. API controller with validation
6. Automatic repository binding

Generated Structure
-------------------

[](#generated-structure)

For a Post model, it creates:

```
app/
├── Http/
│   ├── Controllers/
│   │   └── PostController.php
│   └── Middleware/
│       └── DBTransaction.php
├── Models/
│   └── Post.php
├── Repositories/
│   ├── Interfaces/
│   │   └── PostRepositoryInterface.php
│   └── PostRepository.php
├── Services/
│   └── PostService.php
└── Helpers/
    └── functions.php

```

API Endpoints
-------------

[](#api-endpoints)

Each CRUD generation creates these endpoints:

```
# List all records with pagination
GET /api/posts

# Create new record
POST /api/posts

# Get single record
GET /api/posts/{id}

# Update record
PUT /api/posts/{id}

# Delete record
DELETE /api/posts/{id}
```

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

Credits
-------

[](#credits)

- [Rahul Pathak](https://github.com/rahulpathak1706/package-rahulp)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance41

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

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

4

Last Release

485d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4bb4fe0d9a3f4c585054bac83714d04ef817e2605fa86ef9fdabfb87f5f66cba?d=identicon)[rahulpathak1706](/maintainers/rahulpathak1706)

---

Top Contributors

[![rahulp-webmob](https://avatars.githubusercontent.com/u/184219281?v=4)](https://github.com/rahulp-webmob "rahulp-webmob (6 commits)")

### Embed Badge

![Health badge](/badges/rahulp-crud-generator/health.svg)

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

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[namu/wirechat

A Laravel Livewire messaging app for teams with private chats and group conversations.

54324.5k](/packages/namu-wirechat)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135192.6k5](/packages/statamic-rad-pack-runway)

PHPackages © 2026

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