PHPackages                             mcris112/laravel-hashidable - 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. mcris112/laravel-hashidable

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

mcris112/laravel-hashidable
===========================

LaravelHashidable - Hashids for Laravel Models and Routes

v1.3.6(1w ago)0184MITPHPPHP &gt;=8.0

Since Oct 10Pushed 1w ago1 watchersCompare

[ Source](https://github.com/MCris112/laravel-hashidable)[ Packagist](https://packagist.org/packages/mcris112/laravel-hashidable)[ RSS](/packages/mcris112-laravel-hashidable/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (7)Dependencies (12)Versions (8)Used By (0)

Laravel Hashidable
==================

[](#laravel-hashidable)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1b21f911a3044965d43004d681525c8ae3e86414a536c98f5cac034ec5902911/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d637269733131322f6c61726176656c2d68617368696461626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mcris112/laravel-hashidable)[![License](https://camo.githubusercontent.com/31b4ef9d6b495c2be20e56b4818f866465375e4caebec2606dbc1f86973b3d97/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d637269733131322f6c61726176656c2d68617368696461626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mcris112/laravel-hashidable)

**Laravel Hashidable** provides a seamless way to use [Hashids](https://hashids.org/) in your Laravel models. It automatically handles encoding/decoding of IDs for routing and database lookups, keeping your internal IDs hidden from the public.

This package is an enhanced fork of the original `kayandra/hashidable`, featuring improved type safety, caching support, global helpers, and fluent query builder integration.

✨ Key Features
--------------

[](#-key-features)

- 🛡️ **Automatic Route Model Binding**: Uses hashids in URLs instead of plain integers.
- 🚀 **Performance Caching**: Decoded hashids can be cached to improve performance.
- 🛠️ **Fluent Scopes**: Chainable methods like `whereHashid()`, `orWhereHashid()`, and `findByHashid()`.
- 🧬 **Relation Support**: Easily load relations when finding by hashid using `with()`.
- ✅ **Custom Validation**: Built-in `hashid_exists` rule for validating hashids in requests.
- 🌍 **Global Helpers**: Simple `hashid_encode()` and `hashid_decode()` functions.
- 🎨 **Customizable**: Per-model configuration for salts, lengths, and alphabets.

---

📥 Installation
--------------

[](#-installation)

```
composer require mcris112/laravel-hashidable
```

⚙️ Setup
--------

[](#️-setup)

Add the `Hashidable` trait to your Eloquent model:

```
use Mcris112\LaravelHashidable\Hashidable;
use Illuminate\Database\Eloquent\Model;

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

---

🚀 Usage
-------

[](#-usage)

### Basic Operations

[](#basic-operations)

```
$user = User::find(1);

// Accessing the hashid
echo $user->hashid; // e.g., "3RwQaeoOR1E7qjYy"

// Finding by hashid
$user = User::findByHashid("3RwQaeoOR1E7qjYy");
$user = User::findByHashidOrFail("3RwQaeoOR1E7qjYy");

// Decoding manually via model
$id = User::hashIdDecode("3RwQaeoOR1E7qjYy"); // 1
```

### Advanced Querying &amp; Relations

[](#advanced-querying--relations)

Thanks to the new fluent scopes, you can now load relationships while finding by hashid:

```
// Find with relations (Fluent way)
$user = User::with('posts', 'profile')->findByHashid($hashid);

// Using whereHashid in complex queries
$user = User::whereHashid($hashid)
    ->where('active', true)
    ->with('orders')
    ->firstOrFail();

// Using orWhereHashid
$user = User::where('email', 'admin@example.com')
    ->orWhereHashid($hashid)
    ->first();
```

### Validation Rule

[](#validation-rule)

You can validate that a hashid exists in the database using the `hashid_exists` rule. This automatically decodes the hashid before checking the database.

```
use Illuminate\Http\Request;

public function update(Request $request)
{
    $request->validate([
        'user_id' => 'required|hashid_exists:App\Models\User,id',
    ]);
}
```

The rule accepts two parameters:

1. The **Model class** or **Table name**.
2. The **Database column** (optional, defaults to the model's primary key or `id`).

### Global Helpers

[](#global-helpers)

Decode or encode hashids anywhere without needing a model instance:

```
// Decode hashid for a specific model class
$id = hashid_decode(User::class, "3RwQaeoOR1E7qjYy");

// Encode an ID for a specific model
$hash = hashid_encode(User::class, 1);
```

---

🔗 Route Model Binding
---------------------

[](#-route-model-binding)

This package automatically handles Route Model Binding. Instead of IDs, your routes will use hashids:

```
// routes/web.php
Route::get('/users/{user}', [UserController::class, 'show']);

// In your controller
public function show(User $user)
{
    return view('users.show', compact('user'));
}
```

Generating links automatically uses the hashid:

```
$url = route('users.show', $user); // /users/3RwQaeoOR1E7qjYy
```

---

⚡ Performance Caching
---------------------

[](#-performance-caching)

If you find yourself decoding the same hashids frequently, you can enable caching in the config. This will store the decoded integer ID in your cache store.

```
// config/hashidable.php
'cache' => [
    'enabled' => true,
    'ttl' => 86400, // 24 hours
],
```

---

🛠️ Configuration
----------------

[](#️-configuration)

Publish the configuration file:

```
php artisan vendor:publish --tag=hashidable.config
```

### Global Config (`config/hashidable.php`)

[](#global-config-confighashidablephp)

OptionDescriptionDefault`salt`Unique salt for hash generation`env(HASHIABLE_SALT)``length`Minimum length of generated hash`16``charset`Characters used in the hashid`a-zA-Z0-9``prefix`Optional prefix for hashids`""``suffix`Optional suffix for hashids`""``separator`Separator between prefix/suffix`"-"`### Per-Model Configuration

[](#per-model-configuration)

Implement `HashidableConfigInterface` to customize settings for a specific model:

```
use Mcris112\LaravelHashidable\HashidableConfigInterface;

class Post extends Model implements HashidableConfigInterface
{
    use Hashidable;

    public function hashidableConfig()
    {
        return [
            'length' => 10,
            'prefix' => 'post',
            'separator' => '_',
        ];
    }
}
```

---

❓ FAQ
-----

[](#-faq)

**Q: Are hashes stored in the database?**
A: No. Hashes are calculated dynamically based on your model's ID and salt.

**Q: What happens if I change my salt?**
A: All existing hashids will change. It's recommended to set a permanent salt in your `.env` file (`HASHIABLE_SALT`).

---

📄 License
---------

[](#-license)

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

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance98

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

Recently: every ~239 days

Total

7

Last Release

9d ago

PHP version history (2 changes)V1.0.0PHP &gt;=7.0

V1.3.1PHP &gt;=8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/32046639?v=4)[Cristopher](/maintainers/MCris112)[@MCris112](https://github.com/MCris112)

---

Top Contributors

[![MCris112](https://avatars.githubusercontent.com/u/32046639?v=4)](https://github.com/MCris112 "MCris112 (9 commits)")

---

Tags

laravelhashhashidshashidable

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mcris112-laravel-hashidable/health.svg)

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

###  Alternatives

[vinkla/hashids

A Hashids bridge for Laravel

2.1k14.2M78](/packages/vinkla-hashids)[deligoez/laravel-model-hashid

Generate, Save, and Route Stripe/Youtube-like Hash IDs for Laravel Eloquent Models

166114.2k](/packages/deligoez-laravel-model-hashid)[cybercog/laravel-optimus

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

195578.5k](/packages/cybercog-laravel-optimus)[solspace/craft-freeform

The most flexible and user-friendly form building plugin!

54681.3k19](/packages/solspace-craft-freeform)[torann/hashids

Laravel package for Hashids

54343.7k](/packages/torann-hashids)[balping/laravel-hashslug

Package providing a trait to use Hashids on a model

25191.7k2](/packages/balping-laravel-hashslug)

PHPackages © 2026

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