PHPackages                             96qbhy/hyid - 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. 96qbhy/hyid

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

96qbhy/hyid
===========

hidden your id

0.1.2(7y ago)152.4k1PHP

Since Oct 16Pushed 4y agoCompare

[ Source](https://github.com/qbhy/hyid)[ Packagist](https://packagist.org/packages/96qbhy/hyid)[ RSS](/packages/96qbhy-hyid/feed)WikiDiscussions master Synced 1mo ago

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

hyid
====

[](#hyid)

hide your id. 隐藏你的ID.

使用场景
----

[](#使用场景)

当我们的应用需要提供一个无状态通过ID获取信息的接口，例如 `GET /user/{id}` ，此类接口只要递增ID进行请求，就可以得到我们数据库中所有公开信息，这很显然不是我们想看到的。 `hyid` 可以帮助你隐藏我们不希望用户看到的ID字段，或者其他数字字段。

安装
--

[](#安装)

`composer require 96qbhy/hyid`

### laravel or lumen

[](#laravel-or-lumen)

1. 注册服务提供者 : `Qbhy\Hyid\ServiceProvider::class`
2. 发布配置文件(lumen可以自行复制 `config/hyid.php` 或者安装 `vendor:publish` 命令): `php artisan vendor:publish --provider=Qbhy\Hyid\ServiceProvider`

使用
--

[](#使用)

### 配置

[](#配置)

```
HYID_SECRET=qbhy
HYID_OFFSET=1996
HYID_RANDOM_LENGTH=6

```

> HYID\_RANDOM\_LENGTH 值建议不超过 6

### 代码示例

[](#代码示例)

```
class User extends Model{
    use Qbhy\Hyid\HyidAble;

    // or
    public function getUserId($userId){
        return hyid($userId);
    }

    // or
    public function toArray(){
        $data = parent::toArray();

        $data['id'] = hyid()->encode($data['id']);

        return $data;
    }
}
// decode
```

#### 解码后得到原始的ID

[](#解码后得到原始的id)

```
 public function userinfo($id){
        return User::query()->findOrFail(hyid()->decode($id))->toArray();
 }
```

> UserController

#### 非 laravel 或者 lumen 环境下使用

[](#非-laravel-或者-lumen-环境下使用)

```
// 非 laravel or lumen 下，可以自行实例化 Hyid 类
$secret = 'qbhy';
$offset = 1996;
$hyid = new Hyid($secret,$offset,4);

$encodedId = $hyid->encode(1);
$id = $hyid->decode($encodedId); // 1
```

[qbhy/hyid](https://github.com/qbhy/hyid)

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90% 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 ~1 days

Total

4

Last Release

2759d ago

### Community

Maintainers

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

---

Top Contributors

[![qbhy](https://avatars.githubusercontent.com/u/24204533?v=4)](https://github.com/qbhy "qbhy (9 commits)")[![lilianjin](https://avatars.githubusercontent.com/u/21023027?v=4)](https://github.com/lilianjin "lilianjin (1 commits)")

### Embed Badge

![Health badge](/badges/96qbhy-hyid/health.svg)

```
[![Health](https://phpackages.com/badges/96qbhy-hyid/health.svg)](https://phpackages.com/packages/96qbhy-hyid)
```

###  Alternatives

[vishnubob/wait-for-it

Pure bash script to test and wait on the availability of a TCP host and port

9.8k157.6k3](/packages/vishnubob-wait-for-it)[nodejs-php-fallback/nodejs-php-fallback

Allow you to call node.js module or scripts throught PHP and call a fallback function if node.js is not available

17454.7k8](/packages/nodejs-php-fallback-nodejs-php-fallback)

PHPackages © 2026

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