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

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

erashdan/hashid
===============

Simple package to hash eloquent primary key

1.1.0(5y ago)97.5k2[2 issues](https://github.com/erashdan/hashid/issues)[2 PRs](https://github.com/erashdan/hashid/pulls)PHPPHP &gt;=7.1.3

Since Jan 17Pushed 3y ago1 watchersCompare

[ Source](https://github.com/erashdan/hashid)[ Packagist](https://packagist.org/packages/erashdan/hashid)[ RSS](/packages/erashdan-hashid/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (6)Dependencies (6)Versions (12)Used By (0)

Eloquent Hashid [![Build Status](https://camo.githubusercontent.com/08c4be4f4340b80cf044b66aee9b2b27429eaacf5afd2f6e190853e7d2208936/68747470733a2f2f7472617669732d63692e6f72672f657261736864616e2f6861736869642e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/erashdan/hashid)
============================================================================================================================================================================================================================================================================================

[](#eloquent-hashid-)

- [Installation](#installation)
- [Usage](#usage)
- [Testing](#testing)
- [Credits](#credits)
- [Todo](#todo)

This package hashes the primary key of an eloquent record.

```
// Get Hash ID
$user = \App\User::first();
$user->hashed_id;   //x7LR5oQJleJX60yPpNWV
```

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

[](#installation)

This package can be used in Laravel 5.5 or higher.

You can install the package via composer:

```
composer require erashdan/hashid
```

Laravel's package auto discovery will automatically register the service provider for you.

Then you need to publish the configuration to your project:

```
php artisan vendor:publish --provider="Erashdan\Hashid\HashidServiceProvider" --tag="config"
```

And add the key used for the hashing in .env file

```
HASHID_KEY=SET_YOUR_KEY
```

**OR**

Use Laravel's own app key, change the *key* parameter in `config/hashid.php` to Laravel's application key

```
'key' => env('APP_KEY'),
```

You can also change the length of the resulted hash from `.env` file.

```
HASHID_LENGTH=6
```

Usage
-----

[](#usage)

Eloquent by default doesn't implement hashid, so you should use the trait provided from the package.

```
use Illuminate\Database\Eloquent\Model;
use Erashdan\Hashid\Traits\Hashid;

class Post extends Model
{
    use Hashid;
```

You can then use the hashed\_id attribute on the eloquent object itself.

```
$post = \App\Post::first();
$post->hashed_id; //x7LR5oQJleJX60yPpNWV
```

Or find a resource by hash

```
$post = \App\Post::FindOrFailHashed('x7LR5oQJleJX60yPpNWV');
$post->id; //1
```

Validation
----------

[](#validation)

You can validate if hashed id is existed in model or not

```
    request()->validate([
        'post_id' => 'hashed_exists:' . \App\Post::class
    ]);
```

### Testing

[](#testing)

```
composer test
```

Credits
-------

[](#credits)

- [Emad Rashdan](https://github.com/erashdan)

TODO
----

[](#todo)

```
- [x] Build dev version.
- [] Create command for key generater.
- [] Can store hash id on database.
- [] Can be cached.

```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 66.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 ~143 days

Recently: every ~179 days

Total

6

Last Release

1955d ago

### Community

Maintainers

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

---

Top Contributors

[![erashdan](https://avatars.githubusercontent.com/u/16059897?v=4)](https://github.com/erashdan "erashdan (6 commits)")[![Yazan-Stash](https://avatars.githubusercontent.com/u/28860695?v=4)](https://github.com/Yazan-Stash "Yazan-Stash (2 commits)")[![OthmanAdlan](https://avatars.githubusercontent.com/u/52741796?v=4)](https://github.com/OthmanAdlan "OthmanAdlan (1 commits)")

---

Tags

phplaravelHashed ID

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[ashallendesign/short-url

A Laravel package for creating shortened URLs for your web apps.

1.4k1.9M4](/packages/ashallendesign-short-url)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[laragear/preload

Effortlessly make a Preload script for your Laravel application.

119363.5k](/packages/laragear-preload)[deligoez/laravel-model-hashid

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

16498.0k](/packages/deligoez-laravel-model-hashid)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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