PHPackages                             litepie/hashids - 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. litepie/hashids

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

litepie/hashids
===============

Laravel Sqids (next-gen Hashids) package for encoding and decoding database IDs with route model binding support

v1.0.1(8mo ago)0811MITPHPPHP ^8.2CI passing

Since Aug 24Pushed 8mo agoCompare

[ Source](https://github.com/Litepie/Hashids)[ Packagist](https://packagist.org/packages/litepie/hashids)[ Docs](https://github.com/litepie/hashids)[ GitHub Sponsors](https://github.com/sponsors/litepie)[ RSS](/packages/litepie-hashids/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (9)Versions (3)Used By (1)

Litepie Hashids
===============

[](#litepie-hashids)

[![Latest Version on Packagist](https://camo.githubusercontent.com/52e4bcd28af3c275b28062392683df0bbe58b0d67355fea3a4f053313efcc345/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6974657069652f686173686964732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/litepie/hashids)[![GitHub Tests Action Status](https://camo.githubusercontent.com/6b9953c34d067faad901476a738d5a06300373adfe74773fc5f5e80eef08b5c6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6c6974657069652f686173686964732f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/litepie/hashids/actions?query=workflow%3Atests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/f94a75f8e033c033c4b30f5f65af888bfd72bffb6560f6e9ee78e3b16c3819e6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6c6974657069652f686173686964732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/litepie/hashids/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/a9f6e9748287d5a4aca1d47b651fd79ecb43e4a330953299300d4123215e6192/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6974657069652f686173686964732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/litepie/hashids)

A Laravel package for encoding and decoding database IDs using [Sqids](https://sqids.org/) (next-generation Hashids). This package provides a clean way to obfuscate your database IDs in URLs and API responses while maintaining Laravel conventions.

Features
--------

[](#features)

- 🔢 Encode/decode database IDs using Sqids (next-gen Hashids)
- 🛡️ Built-in profanity filter with customizable blocklist
- 🎭 Eloquent model trait for automatic ID handling
- 🛣️ Route model binding support with encoded IDs
- ✍️ Signed IDs with expiration support
- 🔧 Helper functions for easy usage
- ⚙️ Configurable alphabet, length, and blocklist
- 🚀 Laravel 10, 11, and 12 support
- 🧪 Comprehensive test suite with Pest
- 📝 Full static analysis with PHPStan
- ⚡ Better performance than traditional Hashids

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 10.x, 11.x, or 12.x
- BCMath or GMP extension (automatically handled by Sqids)

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require litepie/hashids
```

The service provider will be automatically registered. To publish the config file:

```
php artisan vendor:publish --provider="Litepie\Hashids\HashidsServiceProvider" --tag="hashids-config"
```

Configuration
-------------

[](#configuration)

The configuration file `config/hashids.php` allows you to customize:

```
return [
    'alphabet' => env('HASHIDS_ALPHABET', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'),
    'length' => env('HASHIDS_LENGTH', 0),
    'blocklist' => env('HASHIDS_BLOCKLIST') ? explode(',', env('HASHIDS_BLOCKLIST')) : null,
];
```

You can also set these values in your `.env` file:

```
HASHIDS_ALPHABET=abcdefghijklmnopqrstuvwxyz1234567890
HASHIDS_LENGTH=10
HASHIDS_BLOCKLIST=word1,word2,word3
```

Usage
-----

[](#usage)

### Helper Functions

[](#helper-functions)

```
// Encode an ID
$hash = hashids_encode(123); // returns something like "bM"

// Decode a hash
$id = hashids_decode('bM'); // returns 123

// Encode multiple values
$hash = hashids_encode([123, 456]); // encode multiple values

// Decode to array
$ids = hashids_decode('86Rf07'); // returns [123, 456]

// Using new Sqids functions (aliases)
$hash = sqids_encode(123); // same as hashids_encode
$id = sqids_decode('bM'); // same as hashids_decode
```

### Facade

[](#facade)

```
use Litepie\Hashids\Facades\Hashids;

$hash = Hashids::encode([123]);
$id = Hashids::decode('bM');
```

### Eloquent Model Trait

[](#eloquent-model-trait)

Add the trait to your Eloquent models:

```
use Litepie\Hashids\Traits\Hashids;

class User extends Model
{
    use Hashids;

    // Your model code...
}
```

#### Available Methods

[](#available-methods)

```
// Get encoded ID
$user = User::find(1);
echo $user->eid; // encoded ID attribute
echo $user->getRouteKey(); // for route model binding

// Find by encoded ID
$user = User::findOrFail('bM');
$user = User::findOrNew('bM');

// Signed IDs (with expiration)
$signedId = $user->getSignedId('+1 hour'); // expires in 1 hour
$signedId = $user->getSignedId(1234567890); // expires at timestamp
$signedId = $user->getSignedId(); // never expires

// Find by signed ID
$user = User::findBySignedId($signedId);
```

#### Route Model Binding

[](#route-model-binding)

The trait automatically supports Laravel's route model binding:

```
// routes/web.php
Route::get('/users/{user}', function (User $user) {
    return $user;
});
```

Now you can use encoded IDs in your URLs:

```
/users/bM instead of /users/1

```

Security
--------

[](#security)

- The alphabet is automatically shuffled for uniqueness
- Built-in profanity filter prevents offensive words in IDs
- Signed IDs include salt verification and optional expiration
- IDs are obfuscated but not encrypted (don't rely on them for security)
- Customizable blocklist for additional word filtering

Why Sqids over Hashids?
-----------------------

[](#why-sqids-over-hashids)

This package uses [Sqids](https://sqids.org/) instead of traditional Hashids, providing:

- ⚡ **Better Performance** - More efficient algorithm
- 🛡️ **Built-in Profanity Filter** - Automatic offensive word prevention
- 🎛️ **Custom Blocklist** - Block specific words from appearing in IDs
- 🔧 **Modern PHP** - Optimized for PHP 8.2+
- 📈 **Active Development** - Regular updates and improvements

Testing
-------

[](#testing)

```
composer test
```

### Running Static Analysis

[](#running-static-analysis)

```
composer analyse
```

### Code Style Fixing

[](#code-style-fixing)

```
composer format
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Lavalite Team](https://github.com/litepie)
- [All Contributors](../../contributors)

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

Support
-------

[](#support)

- **Issues**: [GitHub Issues](https://github.com/litepie/hashids/issues)
- **Documentation**: [README](https://github.com/litepie/hashids#readme)
- **Source**: [GitHub Repository](https://github.com/litepie/hashids)

---

🏢 About
-------

[](#-about)

This package is part of the **Litepie** ecosystem, developed by **Renfos Technologies**.

### Organization Structure

[](#organization-structure)

- **Vendor:** Litepie
- **Framework:** Lavalite
- **Company:** Renfos Technologies

### Links &amp; Resources

[](#links--resources)

- 🌐 **Website:**
- 📚 **Documentation:**
- 💼 **Company:**
- 📧 **Support:**

---

**Built with ❤️ by Renfos Technologies**

*Empowering developers with robust Laravel solutions*

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance59

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

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

Every ~4 days

Total

2

Last Release

262d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

laravelencodinghashidsdecodingobfuscationsqidslitepieid-encodingroute-binding

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/litepie-hashids/health.svg)

```
[![Health](https://phpackages.com/badges/litepie-hashids/health.svg)](https://phpackages.com/packages/litepie-hashids)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[glhd/special

1929.4k](/packages/glhd-special)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k2](/packages/bjuppa-laravel-blog)

PHPackages © 2026

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