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

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

naabster/laravel-eloquent-hashids
=================================

Automatically generate hashids in Laravel for a new Eloquent Model.

1.0.4(9y ago)167.0k5[2 issues](https://github.com/naabster/laravel-eloquent-hashids/issues)MITPHPPHP ^7.0

Since Apr 29Pushed 9y ago1 watchersCompare

[ Source](https://github.com/naabster/laravel-eloquent-hashids)[ Packagist](https://packagist.org/packages/naabster/laravel-eloquent-hashids)[ RSS](/packages/naabster-laravel-eloquent-hashids/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (2)Versions (6)Used By (0)

Laravel 5 Eloquent Hashids
==========================

[](#laravel-5-eloquent-hashids)

Laravel 5 Eloquent Model trait for automatically generating **and persistently saving** [Hashids](http://hashids.org) for new models.
Uses [@vinkla's Laravel 5 Hashids package](https://github.com/vinkla/hashids).

[![Latest Stable Version](https://camo.githubusercontent.com/01fd46522a34e7458dc29f7ce76b8e9a4545225acf62c84e451669716bf1f332/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e616162737465722f6c61726176656c2d656c6f7175656e742d686173686964732e7376673f7374796c653d666c6174)](https://packagist.org/packages/naabster/laravel-eloquent-hashids)[![License](https://camo.githubusercontent.com/c78522b469dca42dedbd78b89b37f0667ae0fae8bc3c5686216ee4659bc11c88/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6e616162737465722f6c61726176656c2d656c6f7175656e742d686173686964732e7376673f7374796c653d666c6174)](https://packagist.org/packages/naabster/laravel-eloquent-hashids)

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

[](#installation)

Require this package, with [Composer](https://getcomposer.org/), in the root directory of your project.

```
composer require naabster/laravel-eloquent-hashids:~1.0
```

You should first install [@vinkla's Laravel 5 Hashids package](https://github.com/vinkla/hashids) according to their installation instructions.

Usage
-----

[](#usage)

Use the `EloquentHashids` trait on your model:

```
use Illuminate\Database\Eloquent\Model;
use Naabster\EloquentHashids\EloquentHashids;

class Book extends Model
{

  use EloquentHashids;

  // Rest of your eloquent model
}
```

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

[](#configuration)

By default the following configuration is used:

#### Hashids Connection

[](#hashids-connection)

The default Hashids Connection is `table.`, so for example for the `Book` model it would be `table.books`. You can set a different connection for your model with `static::getHashidConnection()`:

```
use Illuminate\Database\Eloquent\Model;
use Naabster\EloquentHashids\EloquentHashids;

class Book extends Model
{

  use EloquentHashids;

  public static function getHashidConnection(Model $model)
	{
	  return 'someconnection';
	}
}
```

Make sure you set your connections in your `config/hashids.php` config file (comes with @vinkla's Laravel 5 Hashids package)!

#### Column Name

[](#column-name)

By default the Hashid column is named `uid`. You can set a different column name for your model with `static::getHashidColumn()`:

```
use Illuminate\Database\Eloquent\Model;
use Naabster\EloquentHashids\EloquentHashids;

class Book extends Model
{

  use EloquentHashids;

  public static function getHashidColumn(Model $model)
	{
	  return 'hashid';
	}
}
```

**Attention**

This package generates Hashids for new models and saves them to a column in your database table! To be able to do that, this column must exist in your table.
You should add this column to your model with a [database migration](https://laravel.com/docs/5.3/migrations).

#### Encoding Value

[](#encoding-value)

By default the Value/Number for your Hashid is the `primary Key` attribute of your model (defaults to `id`). You can adjust that any way you want, just make sure it is `Hashids` compatible. Just return another value from `static::getHashidEncodingValue()`:

```
use Illuminate\Database\Eloquent\Model;
use Naabster\EloquentHashids\EloquentHashids;

class Book extends Model
{

  use EloquentHashids;

  public static function getHashidEncodingValue(Model $model)
	{
	  return $model->myId;
	}
}
```

Example
-------

[](#example)

In this example we generate `Hashids` with the connection **bookHashids**, for column **hashid** and with an encoding value of an **array**:

```
use Illuminate\Database\Eloquent\Model;
use Naabster\EloquentHashids\EloquentHashids;

class Book extends Model
{

  use EloquentHashids;

  public static function getHashidConnection(Model $model)
	{
	  return 'bookHashids';
	}

  public static function getHashidColumn(Model $model)
	{
	  return 'hashid';
	}

  public static function getHashidEncodingValue(Model $model)
	{
	  return [$model->id, $model->foreign_key];
	}
}
```

License
-------

[](#license)

The Laravel 5 Eloquent Hashids package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity28

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

Total

5

Last Release

3311d ago

PHP version history (2 changes)1.0.0PHP &gt;=5.4.0

1.0.4PHP ^7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/89d3d9a97977967e6e8c341e7ede0587727cc8252c5c8aa4f472fec9075e3a51?d=identicon)[naabster](/maintainers/naabster)

---

Top Contributors

[![naabster](https://avatars.githubusercontent.com/u/1961461?v=4)](https://github.com/naabster "naabster (2 commits)")[![mtdavidson](https://avatars.githubusercontent.com/u/201792?v=4)](https://github.com/mtdavidson "mtdavidson (1 commits)")

---

Tags

laraveleloquenthashidshashid

### Embed Badge

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

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

###  Alternatives

[silber/bouncer

Eloquent roles and abilities.

3.6k4.4M25](/packages/silber-bouncer)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[veelasky/laravel-hashid

HashId Implementation on Laravel Eloquent ORM

46168.5k3](/packages/veelasky-laravel-hashid)

PHPackages © 2026

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