PHPackages                             geekyants/laravel-usedb - 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. [Database &amp; ORM](/categories/database)
4. /
5. geekyants/laravel-usedb

ActiveLibrary[Database &amp; ORM](/categories/database)

geekyants/laravel-usedb
=======================

Generic CRUD operation

025PHP

Since Jan 29Pushed 5y ago1 watchersCompare

[ Source](https://github.com/usedbjs/laravel-usedb)[ Packagist](https://packagist.org/packages/geekyants/laravel-usedb)[ RSS](/packages/geekyants-laravel-usedb/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (6)Used By (0)

usedb-laravel
=============

[](#usedb-laravel)

### 1) Introduction

[](#1-introduction)

Laravel-usedb is a Generic-CRUD composer package for Laravel apps which eliminates the need to write Apis for each and every model in a Laravel app.

### 2) Motivation

[](#2-motivation)

The idea came out to simplify the job of developers who had to create a similar type of CRUD apis for different projects. Using this package, you can perform CRUD operations to any model in your project.

### 3) Features

[](#3-features)

- **URL**: All the request will counter at the same url i.e. &lt;APP\_URL&gt;/usedb.
- **Generic Controller**: CRUD operations for any Model is handled by the same controller.

### 4)**Installation**

[](#4installation)

```
#COMPOSER
composer require geekyants/laravel-usedb
```

After installation, run the command below to move package's config files to your project config.

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

### 5) Usage

[](#5-usage)

All API request is received at &lt;APP\_URL&gt;/usedb and method type will always of type POST.

The fields which are mandatory, while sending requests are as follows:

- **collection**: It contains the name of the model on which operation has to be performed.
- **operation**: Name of the operation.
- **payload**: It contains different values on the basis of the type of operation.

    Mandatory fields in the payload

    OperationFieldscreatedatafindOnewherefindManyskip, takeupdatedata, wheredeletewhere

1. create data
2. findOne where
3. findMany skip, take
4. update data, where
5. delete where

[Mandatory fields in payload](https://www.notion.so/526fe17b4a5a41f49975d43c2c877ef4)

### Adding Middleware

[](#adding-middleware)

The middleware property of the usedb.php config file contains entries for the middleware to be included with our route. If you would like to assign middleware to routes, make an entry in the middleware. By default, usedb, and model-usedb middlewares are added in the config.

### Setting Model class path

[](#setting-model-class-path)

The modelPath property of usedb.php contains the path of the directory from which the Model class has to be loaded. By default, its value is assigned to "App\\Models\\" which is Laravel's default directory for models.

### Authorization

[](#authorization)

Authorization can be done in two ways: Gates and Policies. After creating them, you need to mention them in the usedb config file.

1. **Gates**: To map the gate to a particular operation of a model, you have to define it in the gates property of type array in the permissions field. Syntax:

```
'gates' => [
		'modelName' => [
        'update' => [],
        'delete' => [],
        'create' => [],
        'findOne' => [],
        'findMany' => []
    ]
]
```

modelName represents the name of the model in which you want to apply gates. `update`, `delete`, `create`, `findOne`, and `findMany` maps to the array of gates to be applied to their respective operations.

2. **Policy**: To policy to a certain operation of a particular model, you have to define it in the `policies` property of type array in the `permissions` field. The syntax for the same:

```
'policies' => [
	'update' => '',
        'delete' => '',
        'create' => '',
        'findOne' => '',
        'findMany' => ''
    ]
]
```

modelName represents the name of the model in which you want to apply policies. `update`, `delete`, `create`, `findOne`, and `findMany` maps to the policy to be applied to their respective operations.

### Association

[](#association)

When you want objects to be returned with their associated models, then you have to mention the property to access child elements from a parent in the `include` property of `payload` field of the JSON provided.

For example, we have an OneToMany relation between Blogs and comments. Now we want to retrieve the blog with its associated comments, then its JSON will be:

```
{
    "collection":"Blog",
    "operation":"findOne",
    "payload": {
        "where":{
            "id": 139
        },
       "include":{
            "comments":{}
        }
    }
}
```

### 6) Example

[](#6-example)

Let's say, we have a Post model having a single property: caption. CRUD example for Post model are as follows:

1. create

```
{
	"collection":"Post",
	"operation":"create",
	"payload": {
			"data":
			{
				"caption": "Caption of the post"
			}
	}
}
```

2. findOne

```
{
	"collection":"Post",
	"operation":"findOne",
	"payload": {
			"where":
			{
				"id": 1
			}
	}
}
```

3. update

```
{
    "collection":"Post",
    "operation":"update",
    "payload": {
        "data": {
            "caption": "changed caption"
        },
        "where": {
            "id" : 10
        }
    }
}
```

4. delete

```
{
    "collection":"Post",
    "operation":"delete",
    "payload": {
        "where": {
            "id" : 3
        }
    }
}
```

5. findMany

```
{
    "collection":"Post",
    "operation":"findMany",
    "payload": {
        "where": {
            "caption": "hello"
        },
        "skip": 1,
        "take": 5
    }
}
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 82.8% 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://avatars.githubusercontent.com/u/19813508?v=4)[Ila Sahu](/maintainers/ilasahu)[@ilasahu](https://github.com/ilasahu)

![](https://www.gravatar.com/avatar/645724a6f4721246f4bf64f6716f0680f08f4565f7c96cc5e3201e57c1f44cb9?d=identicon)[adityaj](/maintainers/adityaj)

![](https://avatars.githubusercontent.com/u/36072496?v=4)[Amar Somani](/maintainers/amarsomani)[@amarsomani](https://github.com/amarsomani)

![](https://avatars.githubusercontent.com/u/46925342?v=4)[Nishan Bende](/maintainers/nishanbende)[@nishanBende](https://github.com/nishanBende)

---

Top Contributors

[![amars29](https://avatars.githubusercontent.com/u/73688673?v=4)](https://github.com/amars29 "amars29 (24 commits)")[![ilasahu](https://avatars.githubusercontent.com/u/19813508?v=4)](https://github.com/ilasahu "ilasahu (5 commits)")

### Embed Badge

![Health badge](/badges/geekyants-laravel-usedb/health.svg)

```
[![Health](https://phpackages.com/badges/geekyants-laravel-usedb/health.svg)](https://phpackages.com/packages/geekyants-laravel-usedb)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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