New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

lingxi/hashids

A Hashids bridge for Laravel
3,325 18

Larablocks Analysis

lingxi/hashids works with Laravel 5 (latest release v0.1.1, Nov 8, 2018), which reached end of life: no more fixes, even for security.

Recommendation checks

Not advised

Not advised: no release or commit in over 2 years.

  • No release or commit in over 2 years
  • Supports only Laravel 5, past end of life
  • No release in the last 12 months (last: Nov 8, 2018)
  • 9 downloads a month (needs 10,000)
  • 18 GitHub stars (needs 100)

State

Likely abandoned
  • No release or commit in over 2 years.
  • Last stable release: Nov 8, 2018.
  • No releases in the last 12 months.
  • First released: Mar 19, 2017.
  • Monthly downloads: 9, down 50% from six months ago.
  • 0 open issues on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Nov 27, 2026.

Install
composer require lingxi/hashids
Latest Version:v0.1.1
Laravel:5
License:MIT
Last Updated:Nov 8, 2018
Links: GitHub  ·  Packagist
Maintainer: RryLee

Laravel Hashids

Latest Stable VersionTotal DownloadsLicense

安装

composer require lingxi/hashids

添加到 app.php

Lingxi\Hashids\HashidsServiceProvider::class
'Hashids' => Lingxi\Hashids\Facades\Hashids::class

Config

php artisan vendor:publish --provider='Lingxi\Hashids\HashidsServiceProvider'
<?php

return [

    'default' => 'main',

    'middleware' => [
        'open' => true,

        // 路由中需要被 decode 的 id
        'route_parameters' => [
            //
        ],

        // 请求参数需要被 decode 的 id
        'request_parameters' => [
            //
        ]
    ],

    // 开启严格模式之后,解密 id 错误会抛出异常
    'strict' => [
        'enable' => true,
        'default' => 0,
    ],

    'connections' => [

        'main' => [
            'prefix' => '',
            'salt' => 'your-salt-string',
            'length' => 'your-length-integer',
            'alphabet' => 'your-alphabet-string',
        ],

    ],

];

Middleware

添加中间件

如果是全局中间件,那么对 route 参数是无法自动 decode 的

\Lingxi\Hashids\Middleware\DecodePublicIdMiddleware::class,

在 config/hashids.php 中去配置需要解密的路由参数以及请求参数

Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Lingxi\Hashids\ModelTraits\PublicId;

class Post extends Model
{
    use PublicId;

    public function comments()
    {
        return $this->morphMany(\App\Comment::class, 'commentable');
    }
}

Then, get public id.

Post::first()->public_id

Debug

php artisan id:en 1 --uri=p

php artisan id:de sdfghjkla;sdjhasjhdfgahjsdjasd

Alternatives to lingxi/hashids

veelasky/laravel-hashid

HashId Implementation on Laravel Eloquent ORM

274,916 48
cybercog/laravel-optimus

An Optimus bridge for Laravel. Id obfuscation based on Knuth's multiplicative ha...

603,567 194
balping/laravel-hashslug

Package providing a trait to use Hashids on a model

213,502 24
elfsundae/laravel-hashid

A simple, elegant way to obfuscate your data by generating reversible, non-seque...

280,051 414

Version History

Version Released PHP Laravel License
v0.1.1 5.5.*|5.6.*|5.7.* MIT
v0.1.0 5.5.*|5.6.* MIT
v0.0.7 >=5.6 ~5.0 MIT
v0.0.6 >=5.6 ~5.0 MIT
v0.0.5 >=5.6 ~5.0 MIT