PHPackages                             iftydev/dynamic-crud - 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. iftydev/dynamic-crud

ActiveLibrary[API Development](/categories/api)

iftydev/dynamic-crud
====================

A dynamic CRUD package for Laravel with Repository Pattern and Interface

v1.0.0(5mo ago)01MITPHPPHP ^8.0|^8.1|^8.2

Since Dec 14Pushed 4mo agoCompare

[ Source](https://github.com/RedwanIfty/dynamic-crud)[ Packagist](https://packagist.org/packages/iftydev/dynamic-crud)[ RSS](/packages/iftydev-dynamic-crud/feed)WikiDiscussions main Synced 1mo ago

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

Dynamic CRUD Package for Laravel
================================

[](#dynamic-crud-package-for-laravel)

[![Latest Version](https://camo.githubusercontent.com/106be80f199e1bf116b10d248ab20e4b4c56a066d3161bf7638d0f10afcdb36a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696674796465762f64796e616d69632d637275642e737667)](https://packagist.org/packages/iftydev/dynamic-crud)[![License](https://camo.githubusercontent.com/156c4c7f2d43983c51c3fa3c9397dca53803ce6457d4d8fc74feaf12a01ff76b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f696674796465762f64796e616d69632d637275642e737667)](https://packagist.org/packages/iftydev/dynamic-crud)

A powerful, production-ready Laravel package that provides dynamic CRUD operations for any Eloquent model using the Repository Pattern with Interface.

✨ Features
----------

[](#-features)

- 🎯 **Dynamic CRUD** - Works with any Eloquent model
- 🏗️ **Repository Pattern** - Clean architecture with Interface/Contract
- 🔒 **Secure** - Model whitelist and validation
- 📄 **API-Based** - RESTful JSON API endpoints
- 🔍 **Advanced Filtering** - Search, range, IN/NOT IN, NULL checks
- 📊 **Pagination** - Built-in pagination support
- 🚀 **Eager Loading** - Optimize queries with relations
- 🎨 **Extensible** - Easy to customize and extend
- ✅ **Laravel 9/10/11** - Compatible with latest Laravel versions

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

[](#-installation)

Install the package via Composer:

```
composer require iftydev/dynamic-crud
```

The package will automatically register itself via Laravel's package auto-discovery.

### Publish Configuration (Optional)

[](#publish-configuration-optional)

```
php artisan vendor:publish --tag=dynamic-crud-config
```

This will create a `config/dynamic-crud.php` file where you can customize the package behavior.

🚀 Quick Start
-------------

[](#-quick-start)

### Basic Usage

[](#basic-usage)

Once installed, you can immediately start using the dynamic CRUD API:

```
# Get all users
GET /api/dynamic-crud/User

# Get a specific user
GET /api/dynamic-crud/User/1

# Create a new user
POST /api/dynamic-crud/User
{
    "name": "John Doe",
    "email": "john@example.com"
}

# Update a user
PUT /api/dynamic-crud/User/1
{
    "name": "Jane Doe"
}

# Delete a user
DELETE /api/dynamic-crud/User/1
```

📚 API Endpoints
---------------

[](#-api-endpoints)

### List All Records

[](#list-all-records)

```
GET /api/dynamic-crud/{Model}
```

**Query Parameters:**

- `per_page` - Items per page (default: 15, use 'all' for no pagination)
- `page` - Page number
- `sort_by` - Field to sort by
- `sort_order` - Sort direction (asc/desc)
- `with` - Comma-separated relations to eager load
- `search` - Search across all searchable fields
- Any model field for exact filtering

**Examples:**

```
# Paginated results
GET /api/dynamic-crud/Post?per_page=20&page=2

# With sorting
GET /api/dynamic-crud/Post?sort_by=created_at&sort_order=desc

# With eager loading
GET /api/dynamic-crud/Post?with=author,comments

# With search
GET /api/dynamic-crud/Post?search=laravel

# With filters
GET /api/dynamic-crud/Post?status=published&category_id=5

# Range filters
GET /api/dynamic-crud/Post?created_at_from=2024-01-01&created_at_to=2024-12-31

# IN filters
GET /api/dynamic-crud/Post?status_in[]=draft&status_in[]=published

# All records (no pagination)
GET /api/dynamic-crud/Post?per_page=all
```

### Get Single Record

[](#get-single-record)

```
GET /api/dynamic-crud/{Model}/{id}
```

**Query Parameters:**

- `with` - Comma-separated relations to eager load

**Example:**

```
GET /api/dynamic-crud/Post/1?with=author,comments,tags
```

### Create Record

[](#create-record)

```
POST /api/dynamic-crud/{Model}
```

**Body:** JSON object with fillable fields

**Example:**

```
POST /api/dynamic-crud/Post
Content-Type: application/json

{
    "title": "My First Post",
    "content": "This is the content",
    "status": "draft",
    "user_id": 1
}
```

### Update Record

[](#update-record)

```
PUT /api/dynamic-crud/{Model}/{id}
PATCH /api/dynamic-crud/{Model}/{id}
```

**Body:** JSON object with fields to update

**Example:**

```
PUT /api/dynamic-crud/Post/1
Content-Type: application/json

{
    "status": "published",
    "published_at": "2024-01-15 10:00:00"
}
```

### Delete Record

[](#delete-record)

```
DELETE /api/dynamic-crud/{Model}/{id}
```

**Example:**

```
DELETE /api/dynamic-crud/Post/1
```

### Bulk Delete

[](#bulk-delete)

```
POST /api/dynamic-crud/{Model}/bulk-delete
```

**Body:**

```
{
    "ids": [1, 2, 3, 4, 5]
}
```

### Get Count

[](#get-count)

```
GET /api/dynamic-crud/{Model}/count
```

**Query Parameters:** Same as list endpoint (filters apply)

**Example:**

```
GET /api/dynamic-crud/Post/count?status=published
```

🔒 Security
----------

[](#-security)

### Model Whitelist

[](#model-whitelist)

For production environments, it's **highly recommended** to whitelist allowed models in `config/dynamic-crud.php`:

```
'allowed_models' => [
    \App\Models\User::class,
    \App\Models\Post::class,
    \App\Models\Comment::class,
],
```

If the whitelist is empty, all models are allowed (not recommended for production).

### Authentication &amp; Authorization

[](#authentication--authorization)

Add authentication middleware in the config:

```
'route_middleware' => [
    'api',
    'auth:sanctum',  // or 'auth:api'
    'throttle:60,1',
],
```

For more granular control, you can create custom middleware or policies.

🎨 Programmatic Usage
--------------------

[](#-programmatic-usage)

You can also use the repository pattern directly in your code:

```
use IftyDev\DynamicCrud\DynamicCrud;
use App\Models\Post;

// Using the helper
$crud = new DynamicCrud();
$repository = $crud->repository(Post::class);

// Or using model instance
$repository = $crud->for(new Post);

// Now use repository methods
$posts = $repository->all(['status' => 'published'], 15);
$post = $repository->find(1);
$newPost = $repository->create(['title' => 'New Post']);
$repository->update(1, ['title' => 'Updated']);
$repository->delete(1);
```

🔧 Advanced Usage
----------------

[](#-advanced-usage)

### Custom Repository

[](#custom-repository)

Create a custom repository for specific models:

```
namespace App\Repositories;

use IftyDev\DynamicCrud\Repositories\BaseCrudRepository;

class PostRepository extends BaseCrudRepository
{
    protected function getSearchableFields(): array
    {
        return ['title', 'content', 'excerpt'];
    }

    public function findPublished()
    {
        return $this->model->where('status', 'published')->get();
    }
}
```

Then bind it in the config:

```
'custom_repositories' => [
    \App\Models\Post::class => \App\Repositories\PostRepository::class,
],
```

### Custom Controller

[](#custom-controller)

Extend the base controller for additional functionality:

```
namespace App\Http\Controllers;

use IftyDev\DynamicCrud\Http\Controllers\CrudController;

class CustomCrudController extends CrudController
{
    protected function validateAndResolveModel(string $modelClass): string
    {
        // Add custom validation logic

        return parent::validateAndResolveModel($modelClass);
    }
}
```

📋 Response Format
-----------------

[](#-response-format)

All endpoints return consistent JSON responses:

### Success Response

[](#success-response)

```
{
    "success": true,
    "message": "Records retrieved successfully",
    "data": {
        // Your data here
    }
}
```

### Error Response

[](#error-response)

```
{
    "success": false,
    "message": "Error message here",
    "errors": {
        // Validation errors (if applicable)
    }
}
```

### Paginated Response

[](#paginated-response)

```
{
    "success": true,
    "message": "Records retrieved successfully",
    "data": {
        "current_page": 1,
        "data": [...],
        "first_page_url": "...",
        "from": 1,
        "last_page": 5,
        "last_page_url": "...",
        "links": [...],
        "next_page_url": "...",
        "path": "...",
        "per_page": 15,
        "prev_page_url": null,
        "to": 15,
        "total": 75
    }
}
```

🛠️ Configuration Options
------------------------

[](#️-configuration-options)

OptionDescriptionDefault`allowed_models`Whitelist of models for CRUD`[]` (all allowed)`default_per_page`Default pagination size`15``max_per_page`Maximum pagination size`100``respect_soft_deletes`Honor soft deletes`true``route_middleware`Middleware for routes`['api']``route_prefix`Route prefix`'dynamic-crud'``enable_query_logging`Log queries for debugging`false``custom_repositories`Custom repository bindings`[]`🚀 Future Enhancements
---------------------

[](#-future-enhancements)

Planned features for future versions:

- ✅ **Validation Rules** - Built-in validation support
- ✅ **Permissions** - Integration with Spatie Permission
- ✅ **JWT Authentication** - JWT support out of the box
- ✅ **File Uploads** - Handle file uploads in CRUD
- ✅ **Export/Import** - CSV/Excel export and import
- ✅ **Audit Logging** - Track all CRUD operations
- ✅ **GraphQL Support** - GraphQL API alongside REST
- ✅ **Caching** - Built-in caching layer
- ✅ **Rate Limiting** - Advanced rate limiting
- ✅ **Webhooks** - Trigger webhooks on CRUD events

📝 Requirements
--------------

[](#-requirements)

- PHP 8.0 or higher
- Laravel 9.x, 10.x, or 11.x

📄 License
---------

[](#-license)

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

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

[](#-contributing)

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

👨‍💻 Author
----------

[](#‍-author)

**IftyDev**

- Email:
- GitHub: [@RedwanIfty](https://github.com/RedwanIfty)

🙏 Support
---------

[](#-support)

If you find this package helpful, please consider giving it a ⭐ on GitHub!

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance73

Regular maintenance activity

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

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

153d ago

### Community

Maintainers

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

---

Top Contributors

[![RedwanIfty](https://avatars.githubusercontent.com/u/91361072?v=4)](https://github.com/RedwanIfty "RedwanIfty (2 commits)")

---

Tags

apilaravelcrudrepositorydynamic

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/iftydev-dynamic-crud/health.svg)

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

###  Alternatives

[essa/api-tool-kit

set of tools to build an api with laravel

52680.5k](/packages/essa-api-tool-kit)[dragon-code/laravel-json-response

Automatically always return a response in JSON format

1118.6k1](/packages/dragon-code-laravel-json-response)

PHPackages © 2026

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