PHPackages                             pivar/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. pivar/hashids

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

pivar/hashids
=============

A Hashids bridge for Laravel

2.4.0(9y ago)0676MITPHPPHP ^5.6.4 || ^7.0

Since Feb 5Pushed 9y ago1 watchersCompare

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

READMEChangelogDependencies (7)Versions (11)Used By (0)

Laravel Hashids
===============

[](#laravel-hashids)

[![hashids](https://cloud.githubusercontent.com/assets/499192/11159205/faa429ae-8a5d-11e5-8c5d-c60a89290c5e.png)](https://cloud.githubusercontent.com/assets/499192/11159205/faa429ae-8a5d-11e5-8c5d-c60a89290c5e.png)

Laravel 5 wrapper for the [Hashids](http://hashids.org) API with multiple connections. [Hashids](http://hashids.org) is a small open-source library that generates short, unique, non-sequential ids from numbers.

```
// Encode integers.
Hashids::encode(4815162342);

// Decode strings.
Hashids::decode('1LLb3b4ck');

// Dependency injection example.
$hashidsManager->encode(911);
```

[![Build Status](https://camo.githubusercontent.com/a6e6d3ab4f3c9e2786052b7ea8a25fde639c9848d4ca55d797336cc216382e92/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f76696e6b6c612f6c61726176656c2d686173686964732f6d61737465722e7376673f7374796c653d666c6174)](https://travis-ci.org/vinkla/laravel-hashids)[![StyleCI](https://camo.githubusercontent.com/599496a642ac6fe46cf49a9354328178c55bc1e5152ddb704f155c84b76de217/68747470733a2f2f7374796c6563692e696f2f7265706f732f33303233373130352f736869656c643f7374796c653d666c6174)](https://styleci.io/repos/30237105)[![Coverage Status](https://camo.githubusercontent.com/49e422eb7c146912554dd8aace630a3ed69b20cbadd4f38bfbaa9fd97a613286/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f76696e6b6c612f686173686964732e7376673f7374796c653d666c6174)](https://scrutinizer-ci.com/g/vinkla/hashids/code-structure)[![Quality Score](https://camo.githubusercontent.com/9ea95b9ffa7f8e3c48bbcf6e855dbcb1214844f08eb29561804db48c2b42b6f9/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f76696e6b6c612f686173686964732e7376673f7374796c653d666c6174)](https://scrutinizer-ci.com/g/vinkla/hashids)[![Latest Version](https://camo.githubusercontent.com/661511f7cd7b2d8fe16b710abd0a17ad3771ac4ded1bc9714e0e0814875f242f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f76696e6b6c612f686173686964732e7376673f7374796c653d666c6174)](https://github.com/vinkla/hashids/releases)[![License](https://camo.githubusercontent.com/9547ddf26daf173461148c72ad7a0b463d04da914eb569e837f4abb0af4a0cb9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f76696e6b6c612f686173686964732e7376673f7374796c653d666c6174)](https://packagist.org/packages/vinkla/hashids)

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

[](#installation)

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

```
$ composer require vinkla/hashids
```

Add the service provider to `config/app.php` in the `providers` array.

```
Vinkla\Hashids\HashidsServiceProvider::class
```

If you want you can use the [facade](http://laravel.com/docs/facades). Add the reference in `config/app.php` to your aliases array.

```
'Hashids' => Vinkla\Hashids\Facades\Hashids::class
```

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

[](#configuration)

Laravel Hashids requires connection configuration. To get started, you'll need to publish all vendor assets:

```
$ php artisan vendor:publish
```

This will create a `config/hashids.php` file in your app that you can modify to set your configuration. Also, make sure you check for changes to the original config file in this package between releases.

#### Default Connection Name

[](#default-connection-name)

This option `default` is where you may specify which of the connections below you wish to use as your default connection for all work. Of course, you may use many connections at once using the manager class. The default value for this setting is `main`.

#### Hashids Connections

[](#hashids-connections)

This option `connections` is where each of the connections are setup for your application. Example configuration has been included, but you may add as many connections as you would like.

Usage
-----

[](#usage)

#### HashidsManager

[](#hashidsmanager)

This is the class of most interest. It is bound to the ioc container as `hashids` and can be accessed using the `Facades\Hashids` facade. This class implements the ManagerInterface by extending AbstractManager. The interface and abstract class are both part of [Graham Campbell's](https://github.com/GrahamCampbell) [Laravel Manager](https://github.com/GrahamCampbell/Laravel-Manager) package, so you may want to go and checkout the docs for how to use the manager class over at that repository. Note that the connection class returned will always be an instance of `Hashids\Hashids`.

#### Facades\\Hashids

[](#facadeshashids)

This facade will dynamically pass static method calls to the `hashids` object in the ioc container which by default is the `HashidsManager` class.

#### HashidsServiceProvider

[](#hashidsserviceprovider)

This class contains no public methods of interest. This class should be added to the providers array in `config/app.php`. This class will setup ioc bindings.

### Examples

[](#examples)

Here you can see an example of just how simple this package is to use. Out of the box, the default adapter is `main`. After you enter your authentication details in the config file, it will just work:

```
// You can alias this in config/app.php.
use Vinkla\Hashids\Facades\Hashids;

Hashids::encode(4815162342);
// We're done here - how easy was that, it just works!

Hashids::decode('doyouthinkthatsairyourebreathingnow');
// This example is simple and there are far more methods available.
```

The Hashids manager will behave like it is a `Hashids\Hashids`. If you want to call specific connections, you can do that with the connection method:

```
use Vinkla\Hashids\Facades\Hashids;

// Writing this…
Hashids::connection('main')->encode($id);

// …is identical to writing this
Hashids::encode($id);

// and is also identical to writing this.
Hashids::connection()->encode($id);

// This is because the main connection is configured to be the default.
Hashids::getDefaultConnection(); // This will return main.

// We can change the default connection.
Hashids::setDefaultConnection('alternative'); // The default is now alternative.
```

If you prefer to use dependency injection over facades like me, then you can inject the manager:

```
use Vinkla\Hashids\HashidsManager;

class Foo
{
	protected $hashids;

	public function __construct(HashidsManager $hashids)
	{
		$this->hashids = $hashids;
	}

	public function bar($id)
	{
		$this->hashids->encode($id)
	}
}

App::make('Foo')->bar();
```

Documentation
-------------

[](#documentation)

There are other classes in this package that are not documented here. This is because the package is a Laravel wrapper of [Ivan Akimov's](https://github.com/ivanakimov) [Hashids package](https://github.com/ivanakimov/hashids.php).

License
-------

[](#license)

Laravel Hashids is licensed under [The MIT License (MIT)](LICENSE).

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 90.4% 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 ~57 days

Total

10

Last Release

3595d ago

Major Versions

1.1.0 → 2.0.02015-06-30

PHP version history (4 changes)1.0.0PHP &gt;=5.4.7

1.1.0PHP &gt;=5.5.9

2.2.1PHP ^5.5.9 || ^7.0

2.4.0PHP ^5.6.4 || ^7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/8bf8bf0b36ca0687111fb03cfdd99f4eefd6f4208d5f554f6a5519eb004cdbda?d=identicon)[pivar](/maintainers/pivar)

---

Top Contributors

[![vinkla](https://avatars.githubusercontent.com/u/499192?v=4)](https://github.com/vinkla "vinkla (123 commits)")[![pivar](https://avatars.githubusercontent.com/u/20150517?v=4)](https://github.com/pivar "pivar (6 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (3 commits)")[![lucasmichot](https://avatars.githubusercontent.com/u/513603?v=4)](https://github.com/lucasmichot "lucasmichot (2 commits)")[![imdanshraaj](https://avatars.githubusercontent.com/u/41511818?v=4)](https://github.com/imdanshraaj "imdanshraaj (1 commits)")[![unicodeveloper](https://avatars.githubusercontent.com/u/2946769?v=4)](https://github.com/unicodeveloper "unicodeveloper (1 commits)")

---

Tags

laravelencryptdecrypthashyoutubebitlyidshashidsobfuscatehashid

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pivar-hashids/health.svg)

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

###  Alternatives

[hashids/hashids

Generate short, unique, non-sequential ids (like YouTube and Bitly) from numbers

5.5k48.6M278](/packages/hashids-hashids)[vinkla/hashids

A Hashids bridge for Laravel

2.1k13.3M73](/packages/vinkla-hashids)[cybercog/laravel-optimus

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

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

Hashids for Yii2

1120.2k](/packages/light-hashids)[elfsundae/laravel-hashid

A simple, elegant way to obfuscate your data by generating reversible, non-sequential, URL-safe identifiers.

415246.3k2](/packages/elfsundae-laravel-hashid)[lingxi/hashids

A Hashids bridge for Laravel

183.3k](/packages/lingxi-hashids)

PHPackages © 2026

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