PHPackages                             tobymaxham/laravel-hashid - 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. tobymaxham/laravel-hashid

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

tobymaxham/laravel-hashid
=========================

This package enables support for hashed ID's in your laravel application.

v1.2(1mo ago)11022MITPHPPHP ^8.2|^8.3|^8.4

Since May 16Pushed 1y ago1 watchersCompare

[ Source](https://github.com/TobyMaxham/laravel-hashid)[ Packagist](https://packagist.org/packages/tobymaxham/laravel-hashid)[ Docs](https://github.com/TobyMaxham/laravel-hashid)[ RSS](/packages/tobymaxham-laravel-hashid/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (8)Versions (12)Used By (0)

[![Laravel HashID](https://camo.githubusercontent.com/16f1bd42318265c2e818b0e4b77d9df74f3793653fdfc77199760a0ec39292bc/68747470733a2f2f736f6369616c6966792e6769742e63692f546f62794d617868616d2f6c61726176656c2d6861736869642f696d6167653f6465736372697074696f6e3d3126666f6e743d52616c65776179266973737565733d31266c616e67756167653d31266f776e65723d31267061747465726e3d436861726c696525323042726f776e2670756c6c733d31267374617267617a6572733d31267468656d653d4c69676874)](https://socialify.git.ci/TobyMaxham/laravel-hashid?description=1&font=Raleway&issues=1&language=1&owner=1&pattern=Charlie%20Brown&pulls=1&stargazers=1&theme=Light)

[![Latest Version on Packagist](https://camo.githubusercontent.com/77190b8cf09d068b14bf90c648ec4f6f9b83fe8b2f35a0d9159b0909064ea615/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f62796d617868616d2f6c61726176656c2d6861736869642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tobymaxham/laravel-hashid)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/c043b0a0bdb365167139f4985bb1387b8daa068bcba9ba5f0f31a31820800b61/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f62796d617868616d2f6c61726176656c2d6861736869642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tobymaxham/laravel-hashid)[![Support me on Patreon](https://camo.githubusercontent.com/cef3268299ac4e91c241041bc589061c18d2c61f9e8393f33907c2fb23fe11be/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e742e7376673f75726c3d6874747073253341253246253246736869656c6473696f2d70617472656f6e2e76657263656c2e617070253246617069253346757365726e616d65253344546f62796d617868616d25323674797065253344706174726f6e73267374796c653d666c6174)](https://patreon.com/Tobymaxham)

This Laravel package ensures that IDs are not directly visible in URLs or other public areas. Instead, they are encoded and, for example, `products/34` is converted to `products/h:J7dVgYxKPwyQejOMnL`.

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

[](#installation)

You can install the package via composer:

```
composer require tobymaxham/laravel-hashid
```

> This package relies on `hashids/hashids`, which requires either the GMP or BCMath extension. GMP is recommended for best performance and should be installed if possible.

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

[](#configuration)

Publish the configuration file with:

```
php artisan vendor:publish --provider="TobyMaxham\HashID\IdHasherServiceProvider"
```

For example, the configuration file `config/hashids.php` looks like this:

```
return [
    'prefix'            => env('HASH_PREFIX', 'h:'),
    'salt'              => env('HASH_SALT', 'your-salt-string'),
    'length'            => env('HASH_LENGTH', 18),
    'alphabet'          => env('HASH_ALPHABET', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'),
    'exception'         => \TobyMaxham\HashId\Exceptions\WrongIdException::class,
    'exception_message' => 'WrongIdException',
    'disable_exception' => false,
];
```

Usage
-----

[](#usage)

### Using the Facade

[](#using-the-facade)

```
use \TobyMaxham\HashId\Facades\IdHasher;

$hash = IdHasher::encodeId(34);
// result: h:J7dVgYxKPwyQejOMnL

$id = IdHasher::decodeId($hash);
// result: 34
```

### Using Dependency Injection

[](#using-dependency-injection)

If you prefer to use dependency injection:

```
use TobyMaxham\HashID\IdHasherManager;

public function show(IdHasherManager $idHasher, $hash)
{
    $id = $idHasher->decodeId($hash);

    return Product::findOrFail($id);
}
```

### Automatically Decode Hash IDs

[](#automatically-decode-hash-ids)

You can use the trait `HashId` in your models to automatically decode hash IDs:

```
class Product extends Model
{
    use Hasher;
}
```

Now you can use them in routes:

```
// web.php
Route::get('products/{product}', 'ProductController@show');

// ProductController.php
class ProductController extends Controller
{
    public function show(Product $product)
    {
        return $product;
    }
}
```

Security
--------

[](#security)

- Make sure your **salt value remains secret** and is not published in your repository.
- The encoded IDs are not encrypted, just encoded. Therefore, they are not secure and should not be used for security purposes.

Changelog
---------

[](#changelog)

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

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

[](#security-vulnerabilities)

If you've found a bug regarding security please mail [mailto:git@maxham.de](git@maxham.de) instead of using the issue tracker.

Support me
----------

[](#support-me)

[![ko-fi](https://camo.githubusercontent.com/201ef269611db7eb6b5d08e9f756ab8980df3014b64492770bdf13a6ed924641/68747470733a2f2f6b6f2d66692e636f6d2f696d672f676974687562627574746f6e5f736d2e737667)](https://ko-fi.com/Z8Z4NZKU)
[![Support me on Patreon](https://camo.githubusercontent.com/cef3268299ac4e91c241041bc589061c18d2c61f9e8393f33907c2fb23fe11be/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e742e7376673f75726c3d6874747073253341253246253246736869656c6473696f2d70617472656f6e2e76657263656c2e617070253246617069253346757365726e616d65253344546f62796d617868616d25323674797065253344706174726f6e73267374796c653d666c6174)](https://patreon.com/Tobymaxham)

Credits
-------

[](#credits)

- [TobyMaxham](https://github.com/TobyMaxham)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance65

Regular maintenance activity

Popularity15

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 85.7% 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 ~148 days

Recently: every ~179 days

Total

8

Last Release

54d ago

Major Versions

v0.4 → v1.02025-02-21

PHP version history (2 changes)v0.1PHP ^8.2

v1.2PHP ^8.2|^8.3|^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/900ab0a66bf701f3fb99a4db54276b4984cf3cf9b55ccad6df65c034f58be85f?d=identicon)[TobyMaxham](/maintainers/TobyMaxham)

---

Top Contributors

[![TobyMaxham](https://avatars.githubusercontent.com/u/5646469?v=4)](https://github.com/TobyMaxham "TobyMaxham (12 commits)")[![NorbertFox](https://avatars.githubusercontent.com/u/12622977?v=4)](https://github.com/NorbertFox "NorbertFox (1 commits)")[![starkh](https://avatars.githubusercontent.com/u/13630412?v=4)](https://github.com/starkh "starkh (1 commits)")

---

Tags

hacktoberfesthacktoberfest-acceptedhacktoberfest-starterhacktoberfest2024laravelhashidtobymaxham

###  Code Quality

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/tobymaxham-laravel-hashid/health.svg)

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

###  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)[torann/hashids

Laravel package for Hashids

54335.1k](/packages/torann-hashids)[glhd/special

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

Add blog functionality to your Laravel project

483.3k2](/packages/bjuppa-laravel-blog)[lingxi/hashids

A Hashids bridge for Laravel

183.3k](/packages/lingxi-hashids)

PHPackages © 2026

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