PHPackages                             byh/laravel-kit - 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. byh/laravel-kit

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

byh/laravel-kit
===============

laravel 工具类

v1.0.0(5y ago)015MITPHPPHP &gt;=7.0

Since Dec 29Pushed 5y ago1 watchersCompare

[ Source](https://github.com/baiyihang-hn/laravelkit)[ Packagist](https://packagist.org/packages/byh/laravel-kit)[ RSS](/packages/byh-laravel-kit/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

安装
--

[](#安装)

- composer require byh/laravel-kit

添加服务
----

[](#添加服务)

在config下app.provider里面添加

```
\Byh\LaravelKit\ApiResponseServiceProvider::class,

```

如果要使用Facade门面，需要在config下app.aliases中添加

```
'ApiResponse' => \Byh\LaravelKit\Facades\ApiResponse::class

```

发布配置
----

[](#发布配置)

php artisan vendor:publish 发布成功后即可在config下发现apiresponse.php文件，该文件用于自定义返回参数设置

使用
--

[](#使用)

```
//成功
public function testSuccess()
{
    return ApiResponse::success('hahaha');
}

//失败
public function testFail()
{
    return ApiResponse::fail('errrrrrr');
}

```

Exceptions
----------

[](#exceptions)

全局异常处理中（app/Exceptions/handle）添加对UnauthorizedException,RequestParamsValidException的处理

```
public function render($request, Throwable $e)
{
    if ($e instanceof NotFoundHttpException) {
        return response()->json([
            'status' => 'error',
            'code' => $e->getStatusCode(),
            'message' => '请求失败',
            'data' => null,
            'error' => '请求地址不存在'
        ], $e->getStatusCode());
    }
    if ($e instanceof UnauthorizedException) {
        return response()->json(ApiResponse::unauthorized($e->getMessage()));
    }
    if ($e instanceof RequestParamsValidException)
        return response()->json(ApiResponse::requestParamsValidError($e->getMessage()));

    return parent::render($request, $e); // TODO: Change the autogenerated stub
}

```

默认值
---

[](#默认值)

### codeMsg

[](#codemsg)

```
'codeMsg' => [
            'success' => ['code' => 200, 'message' => '成功'],
            'fail' => ['code' => 400, 'message' => '失败'],
            'unauthorized' => ['code' => 401, 'message' => '不被允许的请求'],
            'loginExpire' => ['code' => 402, 'message' => '登录已失效'],
        ],

```

### status

[](#status)

```
'status' => [
            'success' => [200, 299],
            'fail' => [400, 499],
            'error' => [500, 599]
        ]

```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

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

1965d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/46ccd3b423657510c67461ecd27da492d96658d5f1bd3d553b06f890c029dc25?d=identicon)[baiyihang](/maintainers/baiyihang)

### Embed Badge

![Health badge](/badges/byh-laravel-kit/health.svg)

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

###  Alternatives

[mpetrovich/dash

A functional programming library for PHP. Inspired by Underscore, Lodash, and Ramda.

10428.9k1](/packages/mpetrovich-dash)

PHPackages © 2026

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