PHPackages                             zhukangs/base-jwt - 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. zhukangs/base-jwt

ActiveLibrary

zhukangs/base-jwt
=================

A base JWT

0.0.1(6y ago)011MITPHP

Since Jan 7Pushed 6y ago1 watchersCompare

[ Source](https://github.com/zhukangs/BaseJwt)[ Packagist](https://packagist.org/packages/zhukangs/base-jwt)[ RSS](/packages/zhukangs-base-jwt/feed)WikiDiscussions master Synced 6d ago

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

### 在Laravel中使用

[](#在laravel中使用)

1.安装扩展包

```
composer require zhukangs/base-jwt
```

2.发布 `src` 下的核心代码

```
php artisan vendor:publish --provider="zhukangs\BaseJwt\ServiceProvider"
```

3.在 `.env` 下加上如下代码

```
JWT_KEY='basejwt'
JWT_ACCESS_EXP=900
JWT_REFRESH_EXP=7200
```

4.编辑 `app\Exceptions\Handler.php`，添加如下代码

```
public function render($request, Exception $exception)
{
    if (Config::get('app.debug') === false) {
        if ($request->ajax()) {
            $message = $exception->getMessage();
            $line    = $exception->getLine();
            $file    = $exception->getFile();
            $code    = $exception->getCode();
            return response()->json(['code' => 500, 'msg' => '请求发生错误!', 'data' => [
                'code'    => $code,
                'line'    => $line,
                'file'    => $file,
                'message' => $message,
            ]]);
        } else {
            return response()->view('base.404');
        }
    }

    //对api的request返回数据格式化
    if($request->is('api/*')){
        //表单验证
        if($exception instanceof ValidationException){
            $error = array_first($exception->errors());
            //return $this->message(array_first($error),$exception->status);
            return $this->message(array_first($error),'error');
        }
    }

    // 将方法拦截到自己的ExceptionReport
    $reporter = ExceptionReport::make($exception);

    if ($reporter->shouldReturn()){
        return $reporter->report();
    }

    return parent::render($request, $exception);
}
```

6.编辑 `app\Http\Kernel.php`，添加如下代码

```
protected $middleware = [
        ...
        \App\Http\Middleware\EnableCrossRequestMiddleware::class,
    ];

protected $routeMiddleware = [
        ..
        'auth.api' => \App\Http\Middleware\AuthApi::class,
    ];
```

7.移除

```
 rm -rf vendor/zhukangs/BaseJwt/src/Api
```

8.登录例子

```
public function toLogin(Request $request)
    {
        $token_data = [
            'user_id' => '$user->id',
            'email' => $request->email,
        ];
        $token = $this->createAccessToken($token_data);

        return $this->success([
            'token' => $token,
            'expires_at' => ($this->getPayload($token))['exp'],
            'email' => $request->email,
        ]);
    }
```

9.需要 `token` 的路由

```
Route::group([
    'middleware' => 'auth.api'
    ], function () {
    Route::get('user', 'AuthController@user');//获取个人信息
});
```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

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

2321d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e974567f274ae548b1ef35c1e75bc39d311dc0f5149a52107818074d0e46d45d?d=identicon)[zhukang0704](/maintainers/zhukang0704)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/zhukangs-base-jwt/health.svg)

```
[![Health](https://phpackages.com/badges/zhukangs-base-jwt/health.svg)](https://phpackages.com/packages/zhukangs-base-jwt)
```

###  Alternatives

[tymon/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

11.5k49.1M350](/packages/tymon-jwt-auth)[kreait/firebase-php

Firebase Admin SDK

2.4k39.7M72](/packages/kreait-firebase-php)[bagisto/bagisto

Bagisto Laravel E-Commerce

26.2k161.6k7](/packages/bagisto-bagisto)[teamtnt/tntsearch

A fully featured full text search engine written in PHP

3.2k3.0M28](/packages/teamtnt-tntsearch)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[php-open-source-saver/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

8359.8M53](/packages/php-open-source-saver-jwt-auth)

PHPackages © 2026

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