PHPackages                             softonic/rest-api-nested-resources - 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. softonic/rest-api-nested-resources

ActiveLibrary[API Development](/categories/api)

softonic/rest-api-nested-resources
==================================

Utilities to work with REST APIs with nested resources

3.0.0(3mo ago)05.5kApache-2.0PHPPHP &gt;=8.5CI passing

Since May 3Pushed 3mo ago5 watchersCompare

[ Source](https://github.com/softonic/rest-api-nested-resources)[ Packagist](https://packagist.org/packages/softonic/rest-api-nested-resources)[ Docs](https://github.com/softonic/rest-api-nested-resources)[ RSS](/packages/softonic-rest-api-nested-resources/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (6)Versions (9)Used By (0)

REST API nested resources
=========================

[](#rest-api-nested-resources)

[![Latest Version](https://camo.githubusercontent.com/d91bffd89a0eb30d9e389c9b5b747118f635441c27c589faad06220a8b27ee10/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f736f66746f6e69632f726573742d6170692d6e65737465642d7265736f75726365732e7376673f7374796c653d666c61742d737175617265)](https://github.com/softonic/rest-api-nested-resources/releases)[![Software License](https://camo.githubusercontent.com/36cfc741510e076bec951c1421a2b1c3a5553e953fcdb378339626a5f33c1e8d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d417061636865253230322e302d626c75652e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://github.com/softonic/rest-api-nested-resources/actions/workflows/build.yml/badge.svg)](https://github.com/softonic/rest-api-nested-resources/actions/workflows/build.yml)[![Total Downloads](https://camo.githubusercontent.com/b702b3d29cc2eb8381a8b6abc28386bb06d9d04feaab342675f6604efebd1f07/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736f66746f6e69632f726573742d6170692d6e65737465642d7265736f75726365732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/softonic/rest-api-nested-resources)[![Average time to resolve an issue](https://camo.githubusercontent.com/630a22940abe1e8cf1857d12afb83bd7f900b5edbda16086331d4c8c7f89ff0d/687474703a2f2f697369746d61696e7461696e65642e636f6d2f62616467652f7265736f6c7574696f6e2f736f66746f6e69632f726573742d6170692d6e65737465642d7265736f75726365732e7376673f7374796c653d666c61742d737175617265)](http://isitmaintained.com/project/softonic/rest-api-nested-resources "Average time to resolve an issue")[![Percentage of issues still open](https://camo.githubusercontent.com/f54112c9cca29d2a56369dbcb7cf0f097b97e2f1ee174856c2d9d0684f387fd8/687474703a2f2f697369746d61696e7461696e65642e636f6d2f62616467652f6f70656e2f736f66746f6e69632f726573742d6170692d6e65737465642d7265736f75726365732e7376673f7374796c653d666c61742d737175617265)](http://isitmaintained.com/project/softonic/rest-api-nested-resources "Percentage of issues still open")

Utilities to work with REST APIs with nested resources

Main features
-------------

[](#main-features)

- MultiKeyModel: allows to have nested resources with composite primary keys
- EnsureModelExists: middleware to validate that a resource exists (used to ensure that a parent resource exists)
- EnsureModelDoesNotExist: middleware to validate that the resource we want to create doesn't already exist
- SubstituteBindings: a personalization of the Laravel's SubstituteBindings middleware to work with nested resources
- SplitPutPatchVerbs: trait that allows the controller to split the "update" method into "modify" (PATCH) and "replace" (PUT) CRUDL methods

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

[](#installation)

You can require the last version of the package using composer

```
composer require softonic/rest-api-nested-resources
```

### Configuration

[](#configuration)

- MultiKeyModel

```
class UserCommentModel extends MultiKeyModel
{
    /**
     * Identifiers to be hashed and used in the real primary and foreign keys.
     */
    protected static array $generatedIds = [
        'id_user_comment' => [
            'id_user',
            'id_comment',
        ],
    ];
}
```

- EnsureModelExists and EnsureModelDoesNotExist

```
class UserCommentController extends Controller
{
    protected function setMiddlewares(Request $request)
    {
        $this->middleware(
            'App\Http\Middleware\EnsureModelExists:App\Models\User,id_user',
            ['only' => ['store', 'update']]
        );

        $this->middleware(
            'App\Http\Middleware\EnsureModelDoesNotExist:App\Models\UserComment,id_user,id_comment',
            ['only' => 'store']
        );
    }
}
```

- SubstituteBindings

```
use App\Models\UserComment;

class UserCommentController extends Controller
{
    public function show(UserComment $userComment)
    {
        ...
    }
}
```

- SplitPutPatchVerbs

```
use App\Models\UserComment;

class UserCommentController extends Controller
{
    use SplitPutPatchVerbs;

    public function modify(UserComment $userComment, Request $request)
    {
        ...
    }

    public function replace(Request $request, string $id_user, string $id_comment)
    {
        ...
    }
}
```

Testing
-------

[](#testing)

`softonic/rest-api-nested-resources` has a [PHPUnit](https://phpunit.de) test suite, and a coding style compliance test suite using [PHP CS Fixer](http://cs.sensiolabs.org/).

To run the tests, run the following command from the project folder.

```
$ docker compose run test
```

To open a terminal in the dev environment:

```
$ docker compose run --entrypoint=bash php
```

License
-------

[](#license)

The Apache 2.0 license. Please see [LICENSE](LICENSE) for more information.

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance78

Regular maintenance activity

Popularity22

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 92.3% 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 ~339 days

Total

5

Last Release

118d ago

Major Versions

1.0.2 → 2.0.02025-02-21

2.0.0 → 3.0.02026-01-20

PHP version history (3 changes)1.0.0PHP &gt;=8.0

2.0.0PHP &gt;=8.3

3.0.0PHP &gt;=8.5

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/524887?v=4)[Joskfg](/maintainers/Joskfg)[@joskfg](https://github.com/joskfg)

---

Top Contributors

[![xaviapa](https://avatars.githubusercontent.com/u/8439057?v=4)](https://github.com/xaviapa "xaviapa (12 commits)")[![Lotykun-Softonic](https://avatars.githubusercontent.com/u/130476160?v=4)](https://github.com/Lotykun-Softonic "Lotykun-Softonic (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisRector

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/softonic-rest-api-nested-resources/health.svg)

```
[![Health](https://phpackages.com/badges/softonic-rest-api-nested-resources/health.svg)](https://phpackages.com/packages/softonic-rest-api-nested-resources)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

74513.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

265103.1M454](/packages/google-gax)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)

PHPackages © 2026

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