PHPackages                             gungcahyadipp/laravel-structured-response - 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. gungcahyadipp/laravel-structured-response

ActiveLibrary[API Development](/categories/api)

gungcahyadipp/laravel-structured-response
=========================================

Structured JSON API response package for Laravel

v1.0.0(2mo ago)011MITPHPPHP ^8.2CI failing

Since May 25Pushed 2mo agoCompare

[ Source](https://github.com/gungcahyadipp/Laravel-Structured-Response)[ Packagist](https://packagist.org/packages/gungcahyadipp/laravel-structured-response)[ RSS](/packages/gungcahyadipp-laravel-structured-response/feed)WikiDiscussions main Synced 1w ago

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

Laravel Structured Response
===========================

[](#laravel-structured-response)

[![Tests](https://github.com/gungcahyadipp/Laravel-Structured-Response/actions/workflows/tests.yml/badge.svg)](https://github.com/gungcahyadipp/Laravel-Structured-Response/actions)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)

Standar response JSON API untuk Laravel 10/11/12/13 dengan resource, relationship, pagination, includes, dan sparse fieldsets — tanpa dependensi yang tidak perlu.

Instalasi
---------

[](#instalasi)

```
composer require gungcahyadipp/laravel-structured-response
```

(Opsional) publish config:

```
php artisan vendor:publish --tag=structured-response-config
```

Quick start
-----------

[](#quick-start)

```
use App\Http\Resources\UserResource;

return ok(UserResource::make($user));
return ok(UserResource::collection(User::paginate(15)));
return invalid($validator->errors());
return not_found('User not found');
```

Resource
--------

[](#resource)

```
use GungCahyadiPP\StructuredResponse\Http\Resources\JsonResource;

class UserResource extends JsonResource
{
    public function type(): string
    {
        return 'users';
    }

    public function attributes(): array
    {
        return [
            'name'  => $this->name,
            'email' => $this->email,
        ];
    }

    public function relationships(): array
    {
        return [
            'posts' => PostResource::collection($this->whenLoaded('posts')),
        ];
    }
}
```

Shorthand helpers
-----------------

[](#shorthand-helpers)

HelperCodeUse case`ok($data, $message = '', $meta = [])`200Success`created($data, $message = '', $meta = [])`201Resource created`no_content()`204Empty success`error($message, $code = 500, $meta = [])`\*Generic error`invalid($errors, $message = 'Validation failed')`422Validation`not_found($message = 'Resource not found')`404Missing resource`unauthorized($message = 'Unauthenticated.')`401Auth required`forbidden($message = 'This action is unauthorized.')`403ForbiddenFluent builder
--------------

[](#fluent-builder)

```
return response_api()
    ->ok(UserResource::make($user))
    ->withMeta(['generated_at' => now()->toISOString()])
    ->send();
```

`ResponseBuilder` adalah immutable — setiap method mengembalikan instance baru.

Pagination
----------

[](#pagination)

Cukup oper paginator (`LengthAwarePaginator` atau `CursorPaginator`). Meta pagination otomatis muncul di `meta.pagination`.

```
return ok(UserResource::collection(User::paginate(15)));
```

Includes
--------

[](#includes)

Mendukung `?include=posts.comments,company`. Aktifkan via `IncludeParser` di config.

Sparse fieldsets
----------------

[](#sparse-fieldsets)

Mendukung `?fields[users]=name,email`. Aktifkan via `FieldsetParser` di config.

Exception integration
---------------------

[](#exception-integration)

**Laravel 11+ (`bootstrap/app.php`):**

```
->withExceptions(function (Exceptions $exceptions) {
    $exceptions->render(
        app(\GungCahyadiPP\StructuredResponse\Exceptions\ExceptionRenderer::class)->render(...)
    );
})
```

**Laravel 10 (`app/Exceptions/Handler.php`):**

```
public function render($request, Throwable $e)
{
    $rendered = app(ExceptionRenderer::class)->render($request, $e);
    return $rendered ?? parent::render($request, $e);
}
```

Testing helper
--------------

[](#testing-helper)

```
use GungCahyadiPP\StructuredResponse\Testing\AssertableJsonResponse;

AssertableJsonResponse::from($response)
    ->assertResponseSuccess()
    ->assertResourceType('users')
    ->assertResourceCount(15)
    ->assertHasPagination();
```

Macros
------

[](#macros)

```
use GungCahyadiPP\StructuredResponse\Support\ResponseBuilder;

ResponseBuilder::macro('accepted', fn () => $this->ok(null, 'Accepted'));
```

Compatibility
-------------

[](#compatibility)

LaravelPHPTestbench10.x8.2^8.011.x8.2 / 8.3^9.012.x8.3^10.013.x8.3 / 8.4^11.0Development
-----------

[](#development)

```
composer install
vendor/bin/pest
vendor/bin/phpstan analyse
vendor/bin/php-cs-fixer check
```

License
-------

[](#license)

MIT — see [LICENSE](LICENSE).

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance88

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

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

61d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/30739832?v=4)[Gung Cahyadi](/maintainers/gungcahyadipp)[@gungcahyadipp](https://github.com/gungcahyadipp)

---

Top Contributors

[![gungcahyadipp](https://avatars.githubusercontent.com/u/30739832?v=4)](https://github.com/gungcahyadipp "gungcahyadipp (2 commits)")

---

Tags

responsejsonapilaravelresource

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/gungcahyadipp-laravel-structured-response/health.svg)

```
[![Health](https://phpackages.com/badges/gungcahyadipp-laravel-structured-response/health.svg)](https://phpackages.com/packages/gungcahyadipp-laravel-structured-response)
```

###  Alternatives

[api-platform/laravel

API Platform support for Laravel

58174.6k17](/packages/api-platform-laravel)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.3M347](/packages/psalm-plugin-laravel)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k30.2M151](/packages/laravel-cashier)[laravel/scout

Laravel Scout provides a driver based solution to searching your Eloquent models.

1.7k55.0M632](/packages/laravel-scout)[nuwave/lighthouse

A framework for serving GraphQL from Laravel

3.5k11.8M118](/packages/nuwave-lighthouse)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

813336.8k3](/packages/defstudio-telegraph)

PHPackages © 2026

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