PHPackages                             sunnanbei/laravel-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. sunnanbei/laravel-response

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

sunnanbei/laravel-response
==========================

laravel-response

1.0.3(5y ago)71642MITPHPPHP ^7.2.5 || ^8.0

Since Jan 19Pushed 5y ago2 watchersCompare

[ Source](https://github.com/TheSunNanbei/laravel-response)[ Packagist](https://packagist.org/packages/sunnanbei/laravel-response)[ Docs](https://github.com/TheSunNanbei/laravel-response.git)[ RSS](/packages/sunnanbei-laravel-response/feed)WikiDiscussions main Synced 3w ago

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

laravel-response
================

[](#laravel-response)

基于laravel封装的response类

这个包的目的是？
--------

[](#这个包的目的是)

在项目开发时，由于获取数据方式不同(ORM、DB、自定义...)，会出现返回格式不统一的情况。
如果使用laravel自带的API资源(Resource)可以完美解决这个问题。
但，并不是每一个资源都需要去创建Resource的。
所以这个package的目的就是为了确保常见场景下，返回格式统一，保证唯一性。

如何使用
----

[](#如何使用)

```
//通过composr安装package
composer require sunnanbei/laravel-response
```

```
use NanBei\Response\Facades\Response;
```

```
//请求成功，输出数据，返回200
return Response::success($data);
```

```
{
    "error_code": 0,
    "message": "请求成功.",
    "data": {},
    "meta": {},
    "error": "",
    "debug": []
}
```

```
{
    "error_code": 0,
    "message": "请求成功.",
    "data": [],
    "meta": {},
    "error": "",
    "debug": []
}
```

```
{
    "error_code": 0,
    "message": "请求成功.",
    "data": {
        "id": 1,
        "name": "北京"
    },
    "meta": {},
    "error": "",
    "debug": []
}
```

```
{
    "error_code": 0,
    "message": "请求成功.",
    "data": [
        {
            "id": 1,
            "name": "北京"
        },
        {
            "id": 2,
            "name": "上海"
        }
    ],
    "meta": {
        "pagination": {
            "total": 100,
            "current_page": 1,
            "last_page": 50,
            "per_page": 2
        }
    },
    "error": "",
    "debug": []
}
```

```
//请求失败，系统异常，返回500
return Response::error();
```

```
//请求失败，返回200
return Response::fail();
```

```
//请求成功，返回201
return Response::created();
```

```
//请求成功，返回204
return Response::noContent();
```

```
//请求成功，返回403
return Response::forbidden();
```

```
//请求成功，返回404
return Response::notFound();
```

```
//接管异常
···
use NanBei\Response\Exceptions\JsonResponse;

class Handler extends ExceptionHandler
{
    use JsonResponse;
···
```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 76.2% 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 ~46 days

Total

3

Last Release

1900d ago

### Community

Maintainers

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

---

Top Contributors

[![TheSunNanbei](https://avatars.githubusercontent.com/u/59078114?v=4)](https://github.com/TheSunNanbei "TheSunNanbei (16 commits)")[![suengoodboy](https://avatars.githubusercontent.com/u/22470250?v=4)](https://github.com/suengoodboy "suengoodboy (4 commits)")[![imxiny](https://avatars.githubusercontent.com/u/24632909?v=4)](https://github.com/imxiny "imxiny (1 commits)")

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[illuminate/events

The Illuminate Events package.

13557.0M2.1k](/packages/illuminate-events)[illuminate/pagination

The Illuminate Pagination package.

12234.1M1.0k](/packages/illuminate-pagination)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M195](/packages/laravel-ai)[illuminate/pipeline

The Illuminate Pipeline package.

9349.2M282](/packages/illuminate-pipeline)[illuminate/session

The Illuminate Session package.

9939.3M850](/packages/illuminate-session)

PHPackages © 2026

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