PHPackages                             wwtg99/restful-helper - 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. wwtg99/restful-helper

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

wwtg99/restful-helper
=====================

0.1.10(8y ago)191MITPHPPHP &gt;=5.6

Since Mar 21Pushed 8y ago1 watchersCompare

[ Source](https://github.com/wwtg99/restful-helper)[ Packagist](https://packagist.org/packages/wwtg99/restful-helper)[ RSS](/packages/wwtg99-restful-helper/feed)WikiDiscussions master Synced 2mo ago

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

Restful query parser trait for Laravel eloquent model
=====================================================

[](#restful-query-parser-trait-for-laravel-eloquent-model)

Add helper traits for restful query.

Installation
============

[](#installation)

```
composer require wwtg99/restful-helper

```

Parse query
===========

[](#parse-query)

This trait parse url queries for eloquent model. Suppose you have a resource controller in route `/users` and connect to User model.

### filters

[](#filters)

Add filterableFields in your model.

```
$filterableFields = ['role'];

```

Then use `/users?role=admin` to get user with role admin.

Supported operators:

- equal: /users?id=1
- equal or greater than: /users?id&gt;=1
- equal or less than: /users?id&lt;=2
- not equal: /users?id!=1
- like: /users?id\*=1

### sorts

[](#sorts)

Use `/users?sort=-role,created_at` to sort by role desc and created\_at asc, comma(,) to separate.

### select fields

[](#select-fields)

Use `/users?fields=name,role,created_at` to show only name, role and created\_at. Also can config `$selectableFields` to restrict selectable fields.

```
$selectableFields = ['name', 'role'];

```

Then only name and role can be selected to show.

Use `fields=count` to count results `/users?fields=count`.

### pagination

[](#pagination)

Use `/users?limit=10&offset=10` to limit 10 and offset 10 records, offset can be omitted, default 0. Also can use `page` and `page_size`, `/users?page=2&page_size=15`, page\_size can be omitted, default 15.

Usage
=====

[](#usage)

Eloquent model trait
--------------------

[](#eloquent-model-trait)

1. Add RestHelper trait in eloquent model.

```
use RestHelperTrait;

```

2. Use index method.

```
$user = User::index()->get();
// Or, use custom inputs array
$user = User::index(request()->all())->get();

```

3. Also combine with other methods.

```
$user = User::index()->where('name', 'admin')->get();

```

Controller trait
----------------

[](#controller-trait)

1. Add RestfulController trait in resource controller.

```
use RestfulControllerTrait;

```

2. Implement getModel method.

```
protected function getModel()
{
    return User::query();
}

```

Model should use RestHelperTrait to have index function.

3. Add controller to routes

```
Route::resource('/path', 'controller');

```

4. Each resource method (index, show, store, update, destroy) has three parts.
    1. parse requests
    2. handle action
    3. response

Override these template functions to change the default behaviors.

Add $creatableFields = \['field1', 'field2'\] to restrict fields to store. Add $updateableFields = \['field1', 'field2'\] to restrict fields to update.

Batch Process
=============

[](#batch-process)

Add new route for batch process. Batch process read content body as json object.

- Get resources:

```
{"GET": [1,2,3]}

```

Use key `GET` and id array as value. Return data or error in the same sequence as query.

- Create resources:

```
{"CREATE": [{"name":"aaa"}, {"name":"bbb"}]}

```

Use key `CREATE` and object array as value. Return data or error in the same sequence as query.

- Update resources:

```
{"UPDATE": {"1": {"name":"ccc"}, "2": {"name": "ddd"}}}

```

Use key `UPDATE`, id and data pairs as value. Return data or error in the same sequence as query.

- Delete resources:

```
{"DELETE": [1,2,3]}

```

Use key `DELETE` and id array as value. Return {"code": 204} or error in the same sequence as query.

Batch Usage
-----------

[](#batch-usage)

1. Add `RestfulControllerTrait` in your Controller

```
class TestController extends Controller
{
    use RestfulControllerTrait;

    protected $creatableFields = ['name', 'email', 'password'];

    protected $updateableFields = ['email'];

    protected function getModel()
    {
        return User::query();
    }
}

```

2. Add route

```
Route::match(['GET', 'POST'], 'test/batch', 'TestController@batch');

```

3. Send batch query POST /test/batch {"GET":\[1,2\],"CREATE":\[{"name":"aaa","email":""}\],"UPDATE":{"1":{"name":"bb"},"2":{"email":""}},"DELETE":\[5,6\]}

Return { "GET": \[{"id":1, "name":"a", "email": ""}, {"id":1, "name":"a", "email": ""}\], "CREATE": \[{"id": 3, "name":"aaa", "email":""}\], "UPDATE": {"1": \["id":1, "name": "bb", "email": ""\], "2": \["id":2, "name":"a", "email":""\], "DELETE": \[{"code":204},{"code":204}\] }

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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 ~9 days

Recently: every ~15 days

Total

11

Last Release

3248d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

laraveldatabasemodeleloquentrestful

### Embed Badge

![Health badge](/badges/wwtg99-restful-helper/health.svg)

```
[![Health](https://phpackages.com/badges/wwtg99-restful-helper/health.svg)](https://phpackages.com/packages/wwtg99-restful-helper)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)[mvanduijker/laravel-model-exists-rule

Validation rule to check if a model exists

22194.5k1](/packages/mvanduijker-laravel-model-exists-rule)

PHPackages © 2026

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