shipsaas/laravel-resource-reducer
Laravel Resource Reducer trims API resource payloads so you only return the fields a client actually needs. Define lean, reusable resource classes, cut response size and query overhead, and keep your JSON output consistent across endpoints.
JsonResource classes.when() / whenLoaded() and query-string parsing. Decision: adopt to move faster on small teams; build in-house if the selection logic needs to be tied tightly to authorization, caching, or OpenAPI schemas.Consider it when:
JsonResource / ResourceCollection classes and want per-request field/relationship trimming without invasive refactors.composer.json packaging—confirm autoloading and package discovery behave as expected).Look elsewhere (or build in-house) when:
fields[] / include semantics, or schema-driven validation—mature alternatives or a dedicated query-builder package are a better fit.For executives (one paragraph): We're evaluating a small, MIT-licensed Laravel helper that lets our API return leaner, request-shaped responses—clients ask for only the fields and relationships they need—without rewriting existing resource classes. It's a low-cost way to ship a payload-reduction capability on our roadmap faster, with the main trade-off being ecosystem maturity: it's a young package with limited adoption and a thin recent release history. Recommendation: pilot in a non-critical endpoint, measure payload/response improvement, and only standardize if it proves its value and maintainer responsiveness holds.
For engineering (summary): A Composer-installed Laravel package providing a fluent API to selectively include/exclude fields, drop relationships and nested resources, with configurable defaults and per-endpoint overrides—designed to sit alongside existing JsonResource definitions. Adopt as a thin convenience layer, not a platform: validate installation in a clean Laravel skeleton (v1.1.1 corrected a composer.json packaging gap), confirm PHP/Laravel version constraints and package discovery, and pin the version. Treat field selection as presentation-layer logic; keep authorization and query optimization in the application layer. Have a fallback plan—native when() / whenLoaded() conditionals—if upstream maintenance stalls, since the capability is largely reproducible in-house.
Decision ask: Approve a time-boxed pilot on one endpoint, with success criteria (measurable payload-size reduction, no regressions, acceptable maintenance signal) and a defined fallback if the dependency proves fragile.
How can I help you explore Laravel packages today?