PHPackages                             naotake51/laravel-recursive-only - 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. naotake51/laravel-recursive-only

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

naotake51/laravel-recursive-only
================================

Register recursiveOnly() extending only() to Model, Collection and Arr.

v1.0.0(4y ago)07MITPHPPHP ^7.1 || ^8.0

Since Apr 21Pushed 3y ago1 watchersCompare

[ Source](https://github.com/naotake51/laravel-recursive-only)[ Packagist](https://packagist.org/packages/naotake51/laravel-recursive-only)[ RSS](/packages/naotake51-laravel-recursive-only/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

laravel-recursive-only
======================

[](#laravel-recursive-only)

Make Laravel's `only` a little more useful.

- recursive
- `*`(any keys)
- callback

Requirements
------------

[](#requirements)

- PHP: `^7.1 || ^8.0`
- Laravel: `^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0`

Install
-------

[](#install)

```
composer require naotake51/laravel-recursive-only

```

Motivation
----------

[](#motivation)

I found deeply nested Laravel's `Resource` to be a pain to define.

I want to write `Resource` more simply.

Using
-----

[](#using)

your model add trait `RecursiveOnly`

```
use Naotake51\RecursiveOnly\Contracts\HasRecursiveOnly;
use Naotake51\RecursiveOnly\Traits\RecursiveOnly;

class Post extends Model implements HasRecursiveOnly
{
    use RecursiveOnly;

    // ...
}
```

call `recursiveOnly`.

- `*` is mean any keys.
- The value can be changed in the callback.

```
$post = Post::with(['author', 'comments'])->find(1);

$data = $post->recursiveOnly([
    'author' => [
        'name'
    ],
    'comments' => [
        '*' => [
            'title' => fn ($value /**, ...parents */) => "# $value", // use callback
            'body',
        ]
    ]
]);

// $data => [
//     'author' => [
//         'name' => '...'
//     ],
//     'comments' => Illuminate\Support\Collection([
//         [
//             'title' => '# ...',
//             'body' => '...',
//         ],
//         ...
//     ])
// ]
```

```
$posts = Post::with(['author', 'comments'])->get();

$data = $posts->recursiveOnly([
    '*' => [
        'author' => [
            'name'
        ],
        'comments' => [
            '*' => [
                'body'
            ]
        ]
    ]
]);

// $data => Illuminate\Support\Collection([
//     [
//         'author' => [
//             'name' => '...'
//         ],
//         'comments' => Illuminate\Support\Collection([
//             [
//                 'body' => '...'
//             ],
//             ...
//         ])
//     ],
//     ...
// ])
```

For arrays, use `Arr::recursiveOnly`

```
$posts = Post::with(['author', 'comments'])->get()->toArray();

$data = Arr::recursiveOnly($posts, [
    '*' => [
        'author' => [
            'name'
        ],
        'comments' => [
            '*' => [
                'body'
            ]
        ]
    ]
]);

// $data => [
//     [
//         'author' => [
//             'name' => '...'
//         ],
//         'comments' => [
//             [
//                 'body' => '...'
//             ],
//             ...
//         ]
//     ],
//     ...
// ]
```

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

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

1533d ago

### Community

Maintainers

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

---

Top Contributors

[![naotake51](https://avatars.githubusercontent.com/u/24481254?v=4)](https://github.com/naotake51 "naotake51 (9 commits)")

---

Tags

collectioneloquentlaravelphpresourcelaravellibrarymodeleloquentcollectionilluminatemacroonly

### Embed Badge

![Health badge](/badges/naotake51-laravel-recursive-only/health.svg)

```
[![Health](https://phpackages.com/badges/naotake51-laravel-recursive-only/health.svg)](https://phpackages.com/packages/naotake51-laravel-recursive-only)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M95](/packages/mongodb-laravel-mongodb)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k32.6M46](/packages/kirschbaum-development-eloquent-power-joins)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[spiritix/lada-cache

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

592456.3k2](/packages/spiritix-lada-cache)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.5M2](/packages/glushkovds-phpclickhouse-laravel)

PHPackages © 2026

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