PHPackages                             shipsaas/laravel-resource-reducer - 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. shipsaas/laravel-resource-reducer

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

shipsaas/laravel-resource-reducer
=================================

Reduce fields &amp; Fasten up your response size using Laravel Resource Reducer

1.1.1(2y ago)479MITPHPPHP &gt;=8.2

Since Sep 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/shipsaas/laravel-resource-reducer)[ Packagist](https://packagist.org/packages/shipsaas/laravel-resource-reducer)[ RSS](/packages/shipsaas-laravel-resource-reducer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (7)Versions (3)Used By (0)

Laravel Resource Reducer from ShipSaaS
======================================

[](#laravel-resource-reducer-from-shipsaas)

[![Build & Test (PHP 8.2 + Laravel 10+)](https://github.com/shipsaas/laravel-resource-reducer/actions/workflows/build.yml/badge.svg)](https://github.com/shipsaas/laravel-resource-reducer/actions/workflows/build.yml)[![codecov](https://camo.githubusercontent.com/401c1543fb12ff6345f1db777669bfc7d042673fc3ca2ab77f23b8eee6e3a557/68747470733a2f2f636f6465636f762e696f2f67682f73686970736161732f6c61726176656c2d7265736f757263652d726564756365722f67726170682f62616467652e7376673f746f6b656e3d616c7438436456556731)](https://codecov.io/gh/shipsaas/laravel-resource-reducer)

Ever thinking about how to speed up your application by optimizing the response? 👀

Laravel Resource Reducer helps you to optimize every API request by:

- Reduce the response's size, get what you need ⭐️
    - Defer execution and allow on-demand data
- Responses to consumers faster 🚀
    - No more BIG FAT JSON every item/request
- Computation only starts when requires, save CPU &amp; memory 😎
- Built-in relationship access by using dot notation 👀
- Eager-loading on steroids (automated eager-loading, no more N+1 pain) 🔋

A simple yet super effective method to skyrocketing your API responding times 🥰

> If you know about GraphQL, To query for data, we need to define which *fields* we want to retrieve. Laravel Resource Reducer is heavily inspired from GraphQL approach. ❤️

Supports
--------

[](#supports)

- Laravel 10 &amp; 11
- PHP 8.2+

### Compatibility

[](#compatibility)

- Single Eloquent Model ✅
- Collection of Eloquent Models ✅
- Pagination ✅ (🟡 we have to use `Resource::collection` for the time being)
- (Planned) Collection of Arrays
- (Planned) Collection of Objects

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

[](#installation)

```
composer require shipsaas/laravel-resource-reducer
```

Usage
-----

[](#usage)

Laravel Resource Reducer is the SuperSet from Laravel Resource, thus we can use the Reducer just like the way we use normal Resource.

For detailed documentation &amp; best practices, check out: [Reducer Documentation](https://reducer.shipsaas.tech)

### Resource Class

[](#resource-class)

Simply migrate your `Resource` class by extending `ShipSaasReducer\Json\JsonReducerResource`, implement the `definitions` method.

The migration is 1:1 migration, no breaking changes 😉.

```
class UserResource extends JsonReducerResource
{
    public function definitions(Request $request): array
    {
        return [
            'id' => fn () => $this->id,
            'email' => fn () => $this->email,
            'created_at' => fn () => $this->created_at,
        ];
    }
}
```

Remember to wrap your accessor in a Closure/Callable. This ensures computation won't start on Runtime (wait for the right time 😉).

**NOTE:** remember to remove the `toArray()` if you are migrating to `JsonReducerResource` 🥹, we handles magic there.

### Return the data

[](#return-the-data)

Same as today as how we are using Laravel Resource:

```
// UserController@index
return UserResource::collection($users)->response();

// UserController@show
return (new UserResource($users->first()))->response();
```

### From API consumers

[](#from-api-consumers)

Use the query `_f` or `_fields`, Reducer supports both ways:

- `http://api/users?_f=id,name,role.name,created_at`
- `http://api/users?_fields[]=id,_fields[]=email`

Testing
-------

[](#testing)

Run `composer test` 😆

Available Tests:

- Unit Testing
- Feature Testing

Contributors
------------

[](#contributors)

- Seth Phat

Contributions &amp; Support the Project
---------------------------------------

[](#contributions--support-the-project)

Feel free to submit any PR, please follow PSR-1/PSR-12 coding conventions and testing is a must.

If this package is helpful, please give it a ⭐️⭐️⭐️. Thank you!

License
-------

[](#license)

MIT License

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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

Total

2

Last Release

791d ago

PHP version history (2 changes)1.0.0PHP ^8.2

1.1.1PHP &gt;=8.2

### Community

Maintainers

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

---

Top Contributors

[![sethsandaru](https://avatars.githubusercontent.com/u/23478115?v=4)](https://github.com/sethsandaru "sethsandaru (14 commits)")

---

Tags

laravellaravel-10laravel-libraryoptimizationphpreducerlaravellaravel-librarylaravel optimizationlaravel resource reducer

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/shipsaas-laravel-resource-reducer/health.svg)

```
[![Health](https://phpackages.com/badges/shipsaas-laravel-resource-reducer/health.svg)](https://phpackages.com/packages/shipsaas-laravel-resource-reducer)
```

###  Alternatives

[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4195.3M84](/packages/livewire-volt)[gehrisandro/tailwind-merge-laravel

TailwindMerge for Laravel merges multiple Tailwind CSS classes by automatically resolving conflicts between them

341682.2k18](/packages/gehrisandro-tailwind-merge-laravel)[nickurt/laravel-akismet

Akismet for Laravel 11.x/12.x/13.x

97139.6k2](/packages/nickurt-laravel-akismet)[whitecube/laravel-timezones

Store UTC dates in the database and work with custom timezones in the application.

106106.2k](/packages/whitecube-laravel-timezones)[sbine/route-viewer

A Laravel Nova tool to view your registered routes.

57215.9k](/packages/sbine-route-viewer)[forxer/laravel-gravatar

A library providing easy gravatar integration in a Laravel project.

4235.6k](/packages/forxer-laravel-gravatar)

PHPackages © 2026

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