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.2(2y ago)072MITPHPPHP &gt;=8.0

Since Oct 10Pushed 2y 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 1mo ago

READMEChangelog (3)Dependencies (4)Versions (4)Used By (0)

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

[](#laravel-hashidable)

> Laravel Hashidable uses [Hashidable](https://github.com/kayandra/hashidable) as main source

\_I made this package because the main package from above never has been updated, that has a mistake in declaring types so when you want to use `User::whereHashid()`

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

[](#installation)

*Note: This package is built to work with Laravel versions greater than 7. It may work in older version, but this has not been tested.*

```
composer require mcris112/laravel-hashidable

```

Setup
-----

[](#setup)

Import the `Hashidable` trait and add it to your model.

```
use Mcris112\LaravelHashidable\Hashidable;

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

Usage
-----

[](#usage)

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

$user->id; // 1
$user->hashid; // 3RwQaeoOR1E7qjYy

User::find(1);

// User::findByHashId( string|array $hashId, array $columns ); Returns a model or a collection of models
User::findByHashId('3RwQaeoOR1E7qjYy');
User::findByHashidOrFail('3RwQaeoOR1E7qjYy');

User::whereHashid('3RwQaeoOR1E7qjYy')->first();

User::hashIdDecode('3RwQaeoOR1E7qjYy'); //Returns the hash decoded,
User::hashIdDecode(['3RwQaeoOR1E7qjYy', ...$hashes]); //This also can be as array
```

### WhereHashid

[](#wherehashid)

This function needs two parameters.

*$hashid* needs to be a *string* and refers a plain hashed id text *$columnId* needs to be a *string* in case that your primary key It is different

```
  User::whereHashid( string $hashid , string $columnId = 'id' )->first();

  //Example

  public function show(string $userId, Request $request)
  {
    // ...
      $user = User::whereHashid($userId)->where('is_email_verified', true)->first();
      // ...
  }
```

### Route Model Binding

[](#route-model-binding)

Assuming we have a route resource defined as follows:

```
Route::apiResource('users', UserController::class);
```

This package does not affect route model bindings, the only difference is, instead of placing the id in the generated route, it uses the hashid instead.

So, `route('users.show', $user)` returns `/users/3RwQaeoOR1E7qjYy`;

When you define your controller that auto-resolves a model in the parameters, it will work as always.

```
public function show(Request $request, User $user)
{
  return $user; // Works just fine
}
```

Configuring
-----------

[](#configuring)

First, publish the config file using:

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

```

The available configuration options are:

```
return [
    /**
     * Length of the generated hashid.
     */
    'length' => 16,

    /**
     * Character set used to generate the hashids.
     */
    'charset' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',

    /**
     * Prefix attached to the generated hash.
     */
    'prefix' => '',

    /**
     * Suffix attached to the generated hash.
     */
    'suffix' => '',

    /**
     * If a prefix of suffix is defined, we use this as a separator
     * between the prefix/suffix.
     */
    'separator' => '-',
];
```

### Per-Model Configuration

[](#per-model-configuration)

You can also extend the global configuration on a per-model basis. To do this, your model should implement the `Mcris112\LaravelHashidable\HashidableConfigInterface` and define the `hashidableConfig()` method on the model.

This method returns an array or subset of options similar to the global configuration.

```
    public function hashidableConfig()
    {
        return ['prefix' => 'app'];
    }
```

FAQs
----

[](#faqs)

 Where are the generated hashes stored?Hashidable does not touch the database to store any sort of metadata. What it does instead is use an internal encoder/decoder to dynamically calculate the hashes.

License
-------

[](#license)

[MIT](/LICENSE.md)

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

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

Total

3

Last Release

912d ago

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

V1.3.1PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/c5f437c968e145ee02a90baec08470c7021b3acbf719891bf6d6e389677abba5?d=identicon)[MCris112](/maintainers/MCris112)

---

Top Contributors

[![MCris112](https://avatars.githubusercontent.com/u/32046639?v=4)](https://github.com/MCris112 "MCris112 (5 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.1k13.3M71](/packages/vinkla-hashids)[deligoez/laravel-model-hashid

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

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

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

192564.1k](/packages/cybercog-laravel-optimus)[torann/hashids

Laravel package for Hashids

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

Package providing a trait to use Hashids on a model

25185.2k2](/packages/balping-laravel-hashslug)[light/hashids

Hashids for Yii2

1120.2k](/packages/light-hashids)

PHPackages © 2026

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