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

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

dialloibrahima/eloquent-hashids
===============================

Hashids obfuscation for Laravel models

v1.0.1(6mo ago)1222↓60%MITPHPPHP ^8.2

Since Dec 10Pushed 6mo agoCompare

[ Source](https://github.com/ibra379/eloquent-hashids)[ Packagist](https://packagist.org/packages/dialloibrahima/eloquent-hashids)[ Docs](https://github.com/ibra379/eloquent-hashids)[ RSS](/packages/dialloibrahima-eloquent-hashids/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (2)Dependencies (15)Versions (3)Used By (0)

Eloquent Hashids
================

[](#eloquent-hashids)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4cbc0105aac74901a5601d102509602be42b12bf507724e72aed89af3aad304e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6469616c6c6f6962726168696d612f656c6f7175656e742d686173686964732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dialloibrahima/eloquent-hashids)[![Total Downloads](https://camo.githubusercontent.com/71a75ab914c1e946abb0a987faf34dc0b2e3255388a8350115237f1a4ec93069/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6469616c6c6f6962726168696d612f656c6f7175656e742d686173686964732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dialloibrahima/eloquent-hashids)[![PHP Version](https://camo.githubusercontent.com/114fb6b4728a8bd9500d21f146cb8888861f43c76409fa335f8553d6f831d3d9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6469616c6c6f6962726168696d612f656c6f7175656e742d686173686964732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dialloibrahima/eloquent-hashids)[![License](https://camo.githubusercontent.com/c17ce0bc0b7e0e7b2aa2532203f7f0bcc6d954f3b4505a806bd32ee4ee8c5c04/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6469616c6c6f6962726168696d612f656c6f7175656e742d686173686964732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dialloibrahima/eloquent-hashids)

A Laravel package that automatically obfuscates Eloquent model IDs in URLs by converting them to reversible hash strings. This improves security and aesthetics by hiding sequential database IDs.

Features
--------

[](#features)

- ✅ **Zero dependencies** - Uses a custom Base62 encoder
- ✅ **Automatic route model binding** - Works seamlessly with Laravel routes
- ✅ **Reversible hashes** - Decode hashids back to original IDs
- ✅ **Per-model configuration** - Customize prefix, suffix, length per model
- ✅ **Laravel 10, 11, 12 support**

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

[](#installation)

```
composer require dialloibrahima/eloquent-hashids
```

Publish the config file:

```
php artisan vendor:publish --tag="eloquent-hashids-config"
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

Add the `Hashidable` trait to your model:

```
use DialloIbrahima\EloquentHashids\Hashidable;

class User extends Model
{
    use Hashidable;
}
```

Now you can use hashids in your URLs:

```
// Get the hashid
$user->hashid; // "aBcD3FgH1jKlM4nP"

// Find by hashid
User::findByHashid('aBcD3FgH1jKlM4nP');
User::findByHashidOrFail('aBcD3FgH1jKlM4nP');

// Route model binding works automatically
Route::get('/users/{user}', function (User $user) {
    return $user;
});
// URL: /users/aBcD3FgH1jKlM4nP
```

### Per-Model Configuration

[](#per-model-configuration)

Implement `HashidableConfigInterface` to customize hashids per model:

```
use DialloIbrahima\EloquentHashids\Contracts\HashidableConfigInterface;
use DialloIbrahima\EloquentHashids\Hashidable;

class Invoice extends Model implements HashidableConfigInterface
{
    use Hashidable;

    public function hashidableConfig(): array
    {
        return [
            'prefix' => 'inv',
            'suffix' => 'v1',
            'length' => 12,
            'separator' => '_',
        ];
    }
}

// Result: inv_aBcD3FgH_v1
```

### API Resources

[](#api-resources)

Expose hashids in your API responses:

```
class UserResource extends JsonResource
{
    public function toArray($request)
    {
        return [
            'id' => $this->hashid,
            'name' => $this->name,
            'email' => $this->email,
        ];
    }
}
```

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

[](#configuration)

```
// config/eloquent-hashids.php

return [
    'length' => 16,           // Minimum hashid length
    'alphabet' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
    'salt' => env('HASHID_SALT', env('APP_KEY', '')),
    'prefix' => '',           // Optional prefix
    'suffix' => '',           // Optional suffix
    'separator' => '-',       // Separator for prefix/suffix
];
```

### Custom Route Binding

[](#custom-route-binding)

If your model already has a custom `resolveRouteBinding()`, use the helper method:

```
class User extends Model
{
    use Hashidable;

    public function resolveRouteBinding($value, $field = null): ?Model
    {
        // Your custom logic here...

        // Then resolve the hashid
        return $this->resolveHashidRouteBinding($value);
    }
}
```

> ⚠️ **Warning**: Changing the `salt` will invalidate all existing hashids!

Testing
-------

[](#testing)

```
composer test
```

Security
--------

[](#security)

Hashids provide **obfuscation, not encryption**. They:

- ✅ Hide sequential IDs
- ✅ Prevent URL enumeration
- ❌ Are NOT cryptographically secure
- ❌ Do NOT replace authentication/authorization

Always use proper authorization in your controllers:

```
public function show(User $user)
{
    $this->authorize('view', $user);
    return $user;
}
```

Credits
-------

[](#credits)

- [Ibrahima Diallo](https://github.com/ibra379)

License
-------

[](#license)

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

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance66

Regular maintenance activity

Popularity16

Limited adoption so far

Community6

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 ~0 days

Total

2

Last Release

207d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/102914230?v=4)[Ibrahima Diallo](/maintainers/ibra379)[@ibra379](https://github.com/ibra379)

---

Top Contributors

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

---

Tags

laraveldialloibrahimaeloquent-hashids

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[spatie/laravel-health

Monitor the health of a Laravel application

87512.0M167](/packages/spatie-laravel-health)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M203](/packages/laravel-ai)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5022.0k](/packages/simplestats-io-laravel-client)[api-platform/laravel

API Platform support for Laravel

58171.8k14](/packages/api-platform-laravel)[harris21/laravel-fuse

Circuit breaker for Laravel queue jobs. Protect your workers from cascading failures.

44855.7k](/packages/harris21-laravel-fuse)

PHPackages © 2026

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