PHPackages                             mamunhoque/laravel-crud-builder - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. mamunhoque/laravel-crud-builder

ActiveLibrary[HTTP &amp; Networking](/categories/http)

mamunhoque/laravel-crud-builder
===============================

Advanced Laravel CRUD Builder - Automatically generate complete CRUD operations with intelligent migration parsing and code generation

v1.0.0(10mo ago)01MITPHPPHP ^8.1CI failing

Since Jun 18Pushed 10mo agoCompare

[ Source](https://github.com/MamunHoque/laravel-crud-builder)[ Packagist](https://packagist.org/packages/mamunhoque/laravel-crud-builder)[ Docs](https://github.com/mamunhoque/laravel-crud-builder)[ RSS](/packages/mamunhoque-laravel-crud-builder/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (2)Used By (0)

Laravel CRUD Builder
====================

[](#laravel-crud-builder)

[![Latest Version on Packagist](https://camo.githubusercontent.com/7a7f8253e6e82e51b11561f1819038441d91c39aadc35d111fbeea40b9644016/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d616d756e686f7175652f6c61726176656c2d637275642d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mamunhoque/laravel-crud-builder)[![GitHub Tests Action Status](https://camo.githubusercontent.com/dd7aad04ebabc7138df67bdc5b87aa0adf03e68092e533395db6f9f8217541f5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6d616d756e686f7175652f6c61726176656c2d637275642d6275696c6465722f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/mamunhoque/laravel-crud-builder/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/eca5a29ef4d34fc448435b940560868a0cd51647990d8d45c27bf278003ac7ee/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6d616d756e686f7175652f6c61726176656c2d637275642d6275696c6465722f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/mamunhoque/laravel-crud-builder/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/67deb7cb6dfec357746bd239db28a19620d4ddcc6bdab0469a6a518c1d53b89e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d616d756e686f7175652f6c61726176656c2d637275642d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mamunhoque/laravel-crud-builder)

An advanced Laravel package that automatically generates complete CRUD operations with intelligent migration parsing and sophisticated code generation. This package goes beyond simple scaffolding by analyzing your existing migration files and generating production-ready code that follows Laravel best practices.

Features
--------

[](#features)

🚀 **Intelligent Migration Parsing**

- Sophisticated analysis of migration files beyond simple regex
- Handles complex column definitions, relationships, and constraints
- Supports both PostgreSQL and MySQL/MariaDB syntax
- Parses foreign keys, indexes, and enum values

🧠 **Smart Code Generation**

- Generates appropriate validation rules based on column types and constraints
- Creates dynamic search keys from text/varchar columns
- Auto-detects and handles file upload fields
- Generates API Resource classes for consistent response formatting
- Implements relationship-aware filtering

🎯 **Complete CRUD Stack**

- **Models** with fillable attributes, relationships, and accessors
- **Controllers** with proper error handling and resource responses
- **Services** with business logic and filtering capabilities
- **Form Requests** with intelligent validation rules
- **API Resources** for consistent data transformation
- **Factories** with realistic fake data generation
- **Tests** (Feature and Unit) with comprehensive coverage

⚙️ **Advanced Configuration**

- Support for multiple middleware groups (admin, public, auth, custom)
- Configurable route prefixes and naming conventions
- Flexible file paths and namespaces
- Soft deletes and timestamps support
- Database compatibility for PostgreSQL, MySQL, and SQLite

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

[](#installation)

You can install the package via Composer:

```
composer require mamunhoque/laravel-crud-builder
```

Publish the configuration file:

```
php artisan vendor:publish --tag="crud-builder-config"
```

Optionally, publish the stub files for customization:

```
php artisan vendor:publish --tag="crud-builder-stubs"
```

The package automatically publishes the `HelperTrait` to `app/Traits/HelperTrait.php` when installed. If you need to republish it:

```
php artisan crud-builder:publish-helper-trait
```

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

[](#quick-start)

### Basic Usage

[](#basic-usage)

Generate a complete CRUD for a model based on an existing migration:

```
php artisan make:advanced-crud Post
```

This will generate:

- `app/Models/Post.php`
- `app/Http/Controllers/PostController.php`
- `app/Services/PostService.php`
- `app/Http/Requests/StorePostRequest.php`
- `app/Http/Requests/UpdatePostRequest.php`
- `app/Http/Resources/PostResource.php`
- `database/factories/PostFactory.php`
- `tests/Feature/PostControllerTest.php`
- `tests/Unit/PostTest.php`
- Routes added to `routes/api.php`

### Selective Generation

[](#selective-generation)

Generate only specific components:

```
# Generate only model and service
php artisan make:advanced-crud Post --model --service

# Generate everything except tests
php artisan make:advanced-crud Post --all --no-tests
```

### Middleware and Route Configuration

[](#middleware-and-route-configuration)

```
# Generate for public API (no authentication)
php artisan make:advanced-crud Post --middleware=public

# Generate for authenticated users
php artisan make:advanced-crud Post --middleware=auth

# Custom route prefix
php artisan make:advanced-crud Post --prefix=v1/api
```

Individual Commands
-------------------

[](#individual-commands)

Generate components individually:

```
# Generate model only
php artisan make:crud-model Post

# Generate service only
php artisan make:crud-service Post

# Generate controller only
php artisan make:crud-controller Post

# Generate request classes only
php artisan make:crud-request Post

# Generate API resource only
php artisan make:crud-resource Post

# Generate tests only
php artisan make:crud-test Post
```

Migration Requirements
----------------------

[](#migration-requirements)

The package analyzes your existing migration files. Ensure your migration follows Laravel conventions:

```
// Example migration: create_posts_table.php
Schema::create('posts', function (Blueprint $table) {
    $table->id();
    $table->string('title');
    $table->string('slug')->unique();
    $table->text('content')->nullable();
    $table->string('featured_image')->nullable();
    $table->enum('status', ['draft', 'published', 'archived'])->default('draft');
    $table->boolean('is_featured')->default(false);
    $table->decimal('price', 8, 2)->nullable();
    $table->foreignId('category_id')->constrained()->onDelete('cascade');
    $table->foreignId('user_id')->constrained()->onDelete('cascade');
    $table->json('metadata')->nullable();
    $table->timestamps();
    $table->softDeletes();
});
```

Generated Code Examples
-----------------------

[](#generated-code-examples)

### Model with Relationships

[](#model-with-relationships)

```
class Post extends Model
{
    use HasFactory, SoftDeletes;

    protected $fillable = [
        'title', 'slug', 'content', 'featured_image', 'status',
        'is_featured', 'price', 'category_id', 'user_id', 'metadata'
    ];

    protected $casts = [
        'is_featured' => 'boolean',
        'price' => 'decimal:2',
        'metadata' => 'array',
    ];

    protected $appends = ['featured_image_url'];

    public function category(): BelongsTo
    {
        return $this->belongsTo(Category::class);
    }

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    public function getFeaturedImageUrlAttribute(): ?string
    {
        if ($this->featured_image) {
            return config('filesystems.disks.s3.url') . '/' . $this->featured_image;
        }
        return null;
    }
}
```

### Service with Intelligent Filtering

[](#service-with-intelligent-filtering)

```
class PostService
{
    use HelperTrait;

    public function index($request): Collection|LengthAwarePaginator|array
    {
        $query = Post::query();

        $query->with(['category', 'user']);

        // Sorting
        $this->applySorting($query, $request);

        // Searching
        $searchKeys = ['title', 'content'];
        $this->applySearch($query, $request->input('search'), $searchKeys);

        // Apply filters
        if ($request->filled('category_id')) {
            $query->where('category_id', $request->input('category_id'));
        }

        if ($request->filled('status')) {
            $query->where('status', $request->input('status'));
        }

        return $this->paginateOrGet($query, $request);
    }
}
```

### Smart Validation Rules

[](#smart-validation-rules)

```
class StorePostRequest extends FormRequest
{
    public function rules(): array
    {
        return [
            'title' => 'required|string|max:255',
            'slug' => 'required|string|max:255|unique:posts,slug',
            'content' => 'nullable|string',
            'featured_image' => 'nullable|string',
            'status' => 'required|in:draft,published,archived',
            'is_featured' => 'nullable|boolean',
            'price' => 'nullable|numeric|min:0',
            'category_id' => 'required|exists:categories,id',
            'user_id' => 'nullable|exists:users,id',
            'metadata' => 'nullable|array',
        ];
    }
}
```

Configuration
-------------

[](#configuration)

The package is highly configurable. Here are some key configuration options:

```
// config/crud-builder.php
return [
    'defaults' => [
        'generate_model' => true,
        'generate_controller' => true,
        'generate_service' => true,
        'generate_requests' => true,
        'generate_resource' => true,
        'generate_tests' => true,
        'generate_routes' => true,
        'generate_factory' => true,
    ],

    'routes' => [
        'middleware_groups' => [
            'admin' => ['auth:api', 'role:admin'],
            'public' => [],
            'auth' => ['auth:api'],
        ],
        'default_middleware' => 'admin',
    ],

    'model' => [
        'use_soft_deletes' => true,
        'use_timestamps' => true,
        'generate_relationships' => true,
        'generate_accessors' => true,
    ],

    'validation' => [
        'generate_smart_rules' => true,
        'include_unique_rules' => true,
        'include_foreign_key_rules' => true,
    ],
];
```

Advanced Features
-----------------

[](#advanced-features)

### Relationship-Aware Filtering

[](#relationship-aware-filtering)

The package automatically generates filters for relationships:

```
// Automatically generated in service
if ($request->filled('category_id')) {
    $query->where('category_id', $request->input('category_id'));
}
```

### File Upload Detection

[](#file-upload-detection)

Automatically detects file upload fields and generates appropriate handling:

```
// In service
$data['featured_image'] = $this->s3FileUpload($request, 'featured_image', 'posts')['path'] ?? null;

// In model
public function getFeaturedImageUrlAttribute(): ?string
{
    if ($this->featured_image) {
        return config('filesystems.disks.s3.url') . '/' . $this->featured_image;
    }
    return null;
}
```

### HelperTrait Features

[](#helpertrait-features)

The package includes a comprehensive `HelperTrait` with useful methods:

```
// Pagination and filtering
$this->applySorting($query, $request);
$this->applySearch($query, $searchValue, $searchKeys);
$this->paginateOrGet($query, $request);

// File uploads
$this->s3FileUpload($request, 'image', 'uploads');
$this->localFileUpload($request, 'file', 'documents');

// API responses
$this->successResponse($data, 'Success message');
$this->errorResponse($errors, 'Error message', 422);

// E-commerce specific filters
$this->applyEComFilters($query, $request);
$this->applyEComSorting($query, $request);
```

### Comprehensive Testing

[](#comprehensive-testing)

Generates both feature and unit tests:

```
// Feature test
public function it_can_create_post()
{
    $data = [
        'title' => fake()->sentence(),
        'content' => fake()->paragraph(),
        'status' => fake()->randomElement(['draft', 'published', 'archived']),
        'category_id' => Category::factory()->create()->id,
    ];

    $response = $this->postJson(route('admin.posts.store'), $data);

    $response->assertStatus(201);
    $this->assertDatabaseHas('posts', $data);
}
```

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Laravel 10.0 or higher
- Existing migration files for the models you want to generate

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Mamun Hoque](https://github.com/mamunhoque)
- [All Contributors](../../contributors)

Roadmap
-------

[](#roadmap)

- Support for API versioning
- GraphQL schema generation
- Custom stub templates
- Integration with Laravel Sanctum
- Automatic API documentation generation
- Support for polymorphic relationships
- Database seeder generation
- Integration with Laravel Horizon for queued operations

License
-------

[](#license)

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

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance53

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

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

Unknown

Total

1

Last Release

329d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/73a9a7de89abc35108928decd67f48a594726d32c1fae56277afe9b460c8260c?d=identicon)[mamunhoque](/maintainers/mamunhoque)

---

Top Contributors

[![MamunHoque](https://avatars.githubusercontent.com/u/5574857?v=4)](https://github.com/MamunHoque "MamunHoque (1 commits)")

---

Tags

apilaravelrestmigrationgeneratorartisancrudcode-generation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mamunhoque-laravel-crud-builder/health.svg)

```
[![Health](https://phpackages.com/badges/mamunhoque-laravel-crud-builder/health.svg)](https://phpackages.com/packages/mamunhoque-laravel-crud-builder)
```

###  Alternatives

[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[bjerke/laravel-bread

A boilerplate package for BREAD operations through REST API in Laravel

115.2k](/packages/bjerke-laravel-bread)

PHPackages © 2026

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