{"id":20857260,"url":"https://github.com/shipsaas/laravel-resource-reducer","last_synced_at":"2025-05-12T07:32:48.906Z","repository":{"id":192497498,"uuid":"686591897","full_name":"shipsaas/laravel-resource-reducer","owner":"shipsaas","description":"Resource Reducer optimizes your API endpoint responses by return what consumers need, defer execution and no more BIG FAT JSON.","archived":false,"fork":false,"pushed_at":"2024-03-13T14:29:26.000Z","size":66,"stargazers_count":45,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-16T23:34:06.025Z","etag":null,"topics":["laravel","laravel-10","laravel-library","optimization","php","reducer"],"latest_commit_sha":null,"homepage":"https://reducer.shipsaas.tech","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shipsaas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-09-03T10:08:53.000Z","updated_at":"2024-06-24T12:45:51.000Z","dependencies_parsed_at":"2024-03-13T15:46:17.612Z","dependency_job_id":null,"html_url":"https://github.com/shipsaas/laravel-resource-reducer","commit_stats":null,"previous_names":["shipsaas/laravel-resource-reducer"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shipsaas%2Flaravel-resource-reducer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shipsaas%2Flaravel-resource-reducer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shipsaas%2Flaravel-resource-reducer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shipsaas%2Flaravel-resource-reducer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shipsaas","download_url":"https://codeload.github.com/shipsaas/laravel-resource-reducer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225129485,"owners_count":17425335,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","laravel-10","laravel-library","optimization","php","reducer"],"created_at":"2024-11-18T04:37:12.047Z","updated_at":"2024-11-18T04:37:12.734Z","avatar_url":"https://github.com/shipsaas.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Resource Reducer from ShipSaaS\n\n[![Build \u0026 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)\n[![codecov](https://codecov.io/gh/shipsaas/laravel-resource-reducer/graph/badge.svg?token=alt8CdVUg1)](https://codecov.io/gh/shipsaas/laravel-resource-reducer)\n\n\nEver thinking about how to speed up your application by optimizing the response? 👀\n\nLaravel Resource Reducer helps you to optimize every API request by:\n\n- Reduce the response's size, get what you need ⭐️\n  - Defer execution and allow on-demand data\n- Responses to consumers faster 🚀\n  - No more BIG FAT JSON every item/request\n- Computation only starts when requires, save CPU \u0026 memory 😎\n- Built-in relationship access by using dot notation 👀\n- Eager-loading on steroids (automated eager-loading, no more N+1 pain) 🔋\n\nA simple yet super effective method to skyrocketing your API responding times 🥰\n\n\u003e If you know about GraphQL, To query for data, we need to define which _fields_ we want to retrieve.\n\u003e Laravel Resource Reducer is heavily inspired from GraphQL approach. ❤️\n\n## Supports\n- Laravel 10 \u0026 11\n- PHP 8.2+\n\n### Compatibility\n- Single Eloquent Model ✅\n- Collection of Eloquent Models ✅\n- Pagination ✅ (🟡 we have to use `Resource::collection` for the time being)\n- (Planned) Collection of Arrays\n- (Planned) Collection of Objects\n\n## Installation\n\n```bash\ncomposer require shipsaas/laravel-resource-reducer\n```\n\n## Usage\n\nLaravel Resource Reducer is the SuperSet from Laravel Resource, thus we can use the Reducer just like \nthe way we use normal Resource.\n\nFor detailed documentation \u0026 best practices, check out: [Reducer Documentation](https://reducer.shipsaas.tech)\n\n### Resource Class\n\nSimply migrate your `Resource` class by extending `ShipSaasReducer\\Json\\JsonReducerResource`, implement the\n`definitions` method.\n\nThe migration is 1:1 migration, no breaking changes 😉.\n\n```php\nclass UserResource extends JsonReducerResource\n{\n    public function definitions(Request $request): array\n    {\n        return [\n            'id' =\u003e fn () =\u003e $this-\u003eid,\n            'email' =\u003e fn () =\u003e $this-\u003eemail,\n            'created_at' =\u003e fn () =\u003e $this-\u003ecreated_at,\n        ];\n    }\n}\n```\n\nRemember to wrap your accessor in a Closure/Callable. \nThis ensures computation won't start on Runtime (wait for the right time 😉). \n\n**NOTE:** remember to remove the `toArray()` if you are migrating to `JsonReducerResource` 🥹, we handles magic there.\n\n### Return the data\n\nSame as today as how we are using Laravel Resource:\n\n```php\n// UserController@index\nreturn UserResource::collection($users)-\u003eresponse();\n\n// UserController@show\nreturn (new UserResource($users-\u003efirst()))-\u003eresponse();\n```\n\n### From API consumers\n\nUse the query `_f` or `_fields`, Reducer supports both ways:\n\n- `http://api/users?_f=id,name,role.name,created_at`\n- `http://api/users?_fields[]=id,_fields[]=email`\n\n## Testing\n\nRun `composer test` 😆\n\nAvailable Tests:\n\n- Unit Testing\n- Feature Testing\n\n## Contributors\n- Seth Phat\n\n## Contributions \u0026 Support the Project\n\nFeel free to submit any PR, please follow PSR-1/PSR-12 coding conventions and testing is a must.\n\nIf this package is helpful, please give it a ⭐️⭐️⭐️. Thank you!\n\n## License\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshipsaas%2Flaravel-resource-reducer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshipsaas%2Flaravel-resource-reducer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshipsaas%2Flaravel-resource-reducer/lists"}