PHPackages                             cirlmcesc/laravel-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. cirlmcesc/laravel-hashids

ActiveLaravel-package[Utility &amp; Helpers](/categories/utility)

cirlmcesc/laravel-hashids
=========================

Automatically generate short, unique, non-sequential ids (like YouTube and Bitly) from numbers for the Eloquent model.

4.0.1(2mo ago)169MITPHPPHP ^8.2CI failing

Since Jun 16Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/cirlmcesc/laravel-hashids)[ Packagist](https://packagist.org/packages/cirlmcesc/laravel-hashids)[ Docs](https://github.com/cirlmcesc/laravel-hashids)[ RSS](/packages/cirlmcesc-laravel-hashids/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (3)Versions (14)Used By (0)

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

[](#laravel-hashids)

[![Latest Stable Version](https://camo.githubusercontent.com/1b9e085866aac034c6cb16632c6bd9b527cc5da61ba4e03b1de9d1c9b1f42711/687474703a2f2f706f7365722e707567782e6f72672f6369726c6d636573632f6c61726176656c2d686173686964732f76)](https://packagist.org/packages/cirlmcesc/laravel-hashids) [![Total Downloads](https://camo.githubusercontent.com/9fb53b728194c22fdf4bf4d181c28b7190f0f93d3960d52510e4fe910bcc3cf5/687474703a2f2f706f7365722e707567782e6f72672f6369726c6d636573632f6c61726176656c2d686173686964732f646f776e6c6f616473)](https://packagist.org/packages/cirlmcesc/laravel-hashids) [![License](https://camo.githubusercontent.com/93dc7680006520dcad3bc2407b9df9d01fd77bfe45613306febbe1e0ce8002d8/687474703a2f2f706f7365722e707567782e6f72672f6369726c6d636573632f6c61726176656c2d686173686964732f6c6963656e7365)](https://packagist.org/packages/cirlmcesc/laravel-hashids) [![PHP Version Require](https://camo.githubusercontent.com/0f179b4d802849bdfb844dcd9c42372423239be3d2aeeb8adf5c40eefcd88a0b/687474703a2f2f706f7365722e707567782e6f72672f6369726c6d636573632f6c61726176656c2d686173686964732f726571756972652f706870)](https://packagist.org/packages/cirlmcesc/laravel-hashids)

---

TL;DR
-----

[](#tldr)

Do not explicitly display the ID of the data in the interface or URI. Use the Trail on the Model to automatically encrypt the ID, and at the same time, it will correctly decrypt the instance of the class you want to inject into the route. It also provides quick methods to encrypt and decrypt the ID when you need. It provides some commands for testing. Inspired by [vinkla/hashids](https://github.com/vinkla/hashids).

---

Getting started
---------------

[](#getting-started)

**Install via composer**

Require this package, with Composer, in the root directory of your project.

```
composer require cirlmcesc/laravel-hashids
```

**Configuration file**

Artisan command will be published to `config/`. The mode of operation can be customized by modifying parameters and attributes.

```
php artisan hashids:install
```

---

Usage
-----

[](#usage)

**Use on Model**

Use Model trait, you can use it quickly. Using trait on the model, you can quickly use it to automatically encrypt the ID when the model is serialized and the value of the field set by `$_only_need_encode_fields`. It is also possible to not set this property and all fields ends with `_id` will be automatically encrypted.You can choose to set the `$_doesnt_need_encode_fields` property to prevent these fields from being encrypted. However, `$_only_need_encode_fields` and `$_doesnt_need_encode_fields` are mutually exclusive. If both are set, an exception will be thrown when the model is serialized into an array. Of course, you can also choose to set the `$_only_encode_id` property to determine whether to encrypt only the ID field. If additional fields need to be encrypted and the field does not end with `_id`, then it is necessary to set `$_only ined_encode_fields` to all fields ending with `_id` plus the fields that require additional encryption Only in this way can it work properly.

```
