PHPackages                             coderscantina/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. [Database &amp; ORM](/categories/database)
4. /
5. coderscantina/hashidable

ActiveLibrary[Database &amp; ORM](/categories/database)

coderscantina/hashidable
========================

An adapted bridge for using hashids in Laravel models.

v1.1.1(1y ago)05.1k1MITPHPPHP ~7.3||^8.0

Since May 19Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/coderscantina/hashidable)[ Packagist](https://packagist.org/packages/coderscantina/hashidable)[ RSS](/packages/coderscantina-hashidable/feed)WikiDiscussions main Synced 2w ago

READMEChangelogDependencies (6)Versions (9)Used By (1)

Hashidable from Coder's Cantina
===============================

[](#hashidable-from-coders-cantina)

[![Laravel Compatibility](https://camo.githubusercontent.com/525f17d4752af9c48bc34e28d98e437b05fe9c3ac6783399953b498236cbc11b/68747470733a2f2f62616467652e6c61726176656c2e636c6f75642f62616467652f636f6465727363616e74696e612f68617368696461626c65)](https://packagist.org/packages/coderscantina/hashidable)

> An adapted bridge for using [laravel-hashids](https://github.com/vinkla/laravel-hashids) in Laravel models.

Features
--------

[](#features)

- Hashid route model binding
- Individual salt per model
- Optional individual configuration per model
- Helper methods for encoding, decoding and finding by hashid
- Collection support for working with multiple hashids
- Performance optimizations with factory caching

🏗 Install
---------

[](#-install)

Install the package via composer using this command:

```
composer require coderscantina/hashidable
```

⚙️ Usage
--------

[](#️-usage)

Add the Hashidable trait to your model

```
use CodersCantina\Hashidable;

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

### Route Model Binding

[](#route-model-binding)

Expose the hashid in a resource

```
class FooResource extends JsonResource
{
    /**
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->getRouteKey(),
        ];
    }
}
```

Resolve the model via hashid in a controller

```
/**
* @param  \App\Models\Foo  $foo
* @return \Illuminate\Http\Response
*/
public function show(Foo $foo)
{
    return new FooResource($foo);
}
```

### Working with Single Models/IDs

[](#working-with-single-modelsids)

Static methods to work with hashIds:

```
Foo::encodeHashId(1);             // Convert ID to hashid
Foo::decodeHashId('A3');          // Convert hashid to ID
Foo::findByHashId('A3');          // Find model by hashid
Foo::findByHashIdOrFail('A3');    // Find model by hashid or throw exception
```

### Working with Collections/Arrays

[](#working-with-collectionsarrays)

Methods for working with multiple models or IDs:

```
// Encode multiple IDs
Foo::encodeHashIds([1, 2, 3]);    // Returns array of hashids

// Decode multiple hashids
Foo::decodeHashIds(['A3', 'B7']); // Returns array of IDs

// Find multiple models by hashids
Foo::findByHashIds(['A3', 'B7']); // Returns collection of models
```

### Custom Configuration

[](#custom-configuration)

Overwrite config with a model like `App\User::class`

```
# config/hashids.php

'connections' => [

    'main' => [
        'salt' => env('HASHIDS_SALT'),
        'length' => 8,
        'alphabet' => '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ',
    ],

    \App\User::class => [
        'salt' => env('HASHIDS_SALT'),
        'length' => 5,
        'alphabet' => '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ',
    ],

],
```

See for more information [Route Model Binding](https://laravel.com/docs/master/routing#route-model-binding)

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance69

Regular maintenance activity

Popularity17

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.3% 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 ~94 days

Recently: every ~34 days

Total

8

Last Release

469d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/605b58449a3fff7658eba249cf6cad34ed7a577f7d72f673c1b858ce3a97f311?d=identicon)[badmike](/maintainers/badmike)

---

Top Contributors

[![badmike](https://avatars.githubusercontent.com/u/1019002?v=4)](https://github.com/badmike "badmike (12 commits)")[![kburton-dev](https://avatars.githubusercontent.com/u/10101978?v=4)](https://github.com/kburton-dev "kburton-dev (1 commits)")

---

Tags

laravelhashidsLaravel-hashids

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k54.1M11.1k](/packages/illuminate-database)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k29.9M42](/packages/kirschbaum-development-eloquent-power-joins)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8723.1M23](/packages/yajra-laravel-oci8)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.4M2](/packages/glushkovds-phpclickhouse-laravel)[veelasky/laravel-hashid

HashId Implementation on Laravel Eloquent ORM

45180.7k3](/packages/veelasky-laravel-hashid)[lemaur/eloquent-publishing

207.8k1](/packages/lemaur-eloquent-publishing)

PHPackages © 2026

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