PHPackages                             mrjmpl3/laravel-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. mrjmpl3/laravel-restful-helper

AbandonedLibrary[Utility &amp; Helpers](/categories/utility)

mrjmpl3/laravel-restful-helper
==============================

Laravel Helper to Restful projects

3.1.0(6y ago)11.2kMITPHPPHP ^7.1.3CI failing

Since May 3Pushed 4y ago1 watchersCompare

[ Source](https://github.com/MrJmpl3-PHP-Laravel/package-restful-helper)[ Packagist](https://packagist.org/packages/mrjmpl3/laravel-restful-helper)[ Docs](https://github.com/MrJmpl3/Laravel_Restful_Helper)[ RSS](/packages/mrjmpl3-laravel-restful-helper/feed)WikiDiscussions master Synced 2mo ago

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

LARAVEL RESTFUL HELPER
======================

[](#laravel-restful-helper)

Install
-------

[](#install)

Via Composer

```
$ composer require mrjmpl3/laravel-restful-helper
```

Usage
-----

[](#usage)

This packages make queries depends of the request, like GraphQL.

### Requests

[](#requests)

- **Filter data:** /product?column=value&amp;column2=value2
- **Sort data:** /product?sort=-column1,column2
    - With the negative prefix = desc
    - Without the negative prefix = asc
- **Fields o Select data:** /product?fields=column1,column2,column3,column4
- **Paginate and Per Page:** /product?paginate=true&amp;per\_page=5
- **Embed:** /product?embed=relationfunction

### Code

[](#code)

#### To Collection

[](#to-collection)

```
// Create a simple instance of model where you want apply the queries
$model = new Product();
$responseHelper = new ApiRestHelper($model);

// The method 'toCollection' return a collection with all data filtered
$response = $responseHelper->toCollection();

```

#### To Model

[](#to-model)

```
// Create a simple instance of model where you want apply the queries
$model = new Product();
$responseHelper = new ApiRestHelper($model);

// The method 'toModel' return a model with all data filtered
$response = $responseHelper->toModel();

```

#### From Builder to Collection

[](#from-builder-to-collection)

```
// Important! Don't close the query with get() or paginate()
$query = Product::where('state', = , 1);
$responseHelper = new ApiRestHelper($query);

// The method 'toCollection' return a collection with all data filtered
$response = $responseHelper->toCollection();

```

#### Relations

[](#relations)

- In model, add array like next example:

    ```
    public $apiAcceptRelations = [
        'post'
    ];

    ```

    Where 'post' is the function name of relation
- In the API Resources, use the function embed

    ```
    public function toArray($request) {
        $embed = (new ApiRestHelper)->getEmbed();

        return [
          'id' => $this->id,
          'name' => $this->name,
          $this->mergeWhen(array_key_exists('post', $embed), [
              'post' => $this->getPostResource($embed),
          ]),
          'created_at' => $this->created_at,
          'updated_at' => $this->updated_at,
        ];
    }

    private function getPostResource($embedRequest) {
      $postResource = NULL;

      if (array_key_exists('local', $embed)) {
          $postRelation = $this->local();
          $fieldsFromEmbed = (new ApiRestHelper($postRelation->getModel()))->getEmbedField('post');

          if(!empty($fieldsFromEmbed)) {
              $postResource = new PostResource($postRelation->select($fieldsFromEmbed)->first());
          } else {
              $postResource = new PostResource($postRelation->first());
          }
      }

      return $postResource;
    }

    ```

#### Transformers

[](#transformers)

- In model, add array like next example:

```
public $apiTransforms = [
    'id' => 'code'
];

```

Where 'id' is the db column name , and 'code' is the column rename to response

- In the API Resources, use the array $apiTransforms

```
$apiHelper = new ApiRestHelper($this);

return [
    $apiHelper->getKeyTransformed('id') => $this->id,
    'name' => $this->name,
    'created_at' => $this->created_at,
    'updated_at' => $this->updated_at,
];

```

- To used fields in API Resources , You can combine with transformers fields

```
$apiHelper = new ApiRestHelper($this);

return [
    $this->mergeWhen($apiHelper->existInFields('id') && !is_null($this->id), [
        $this->transforms['id'] => $this->id
    ]),
    $this->mergeWhen($apiHelper->existInFields('name') && !is_null($this->name), [
        'name' => $this->name
    ]),
]

```

#### Exclude Fields in Filter

[](#exclude-fields-in-filter)

- In model, add array like next example:

```
public $apiExcludeFilter = [
    'id'
];

```

Where 'id' is the db column name to exclude

Change log
----------

[](#change-log)

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

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.md) for more information.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity67

Established project with proven stability

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

Recently: every ~30 days

Total

19

Last Release

2122d ago

Major Versions

1.7 → 2.0.02018-11-11

2.1.3 → 3.0.02019-01-05

3.1.0 → 4.0.0-alpha.12020-03-09

PHP version history (2 changes)1.6.0PHP ^7.1.3

4.0.0-alpha.5PHP ^7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/39c38d8f051ba6afb0e14cb3abb0c5bea3555d41844c8828fb9f949222085119?d=identicon)[MrJmpl3](/maintainers/MrJmpl3)

---

Top Contributors

[![MrJmpl3](https://avatars.githubusercontent.com/u/21302114?v=4)](https://github.com/MrJmpl3 "MrJmpl3 (72 commits)")

---

Tags

laravelhelperrestfulMrJmpl3Laravel\_Restful\_Helper

### Embed Badge

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

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[glhd/special

1929.4k](/packages/glhd-special)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k2](/packages/bjuppa-laravel-blog)

PHPackages © 2026

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