PHPackages                             atldays/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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. atldays/laravel-hashids

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

atldays/laravel-hashids
=======================

Laravel Hashids package for generating short hashed identifiers for models and other numeric values.

v2.0.0(1mo ago)024↓25%MITPHPPHP ^8.2CI passing

Since Apr 15Pushed 1w agoCompare

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

READMEChangelog (4)Dependencies (7)Versions (4)Used By (0)

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

[](#laravel-hashids)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ded6a2fc9e55cb91828fb9c09ca210377b8814945d7b5b6fd2093ca41271aeb9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61746c646179732f6c61726176656c2d686173686964732e7376673f6c6f676f3d7061636b6167697374267374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/atldays/laravel-hashids)[![Total Downloads](https://camo.githubusercontent.com/b2ed9b002dc1fc93bd5bc1e9d3f4e6ac225e1a23a2838c08a282f457032ebb1f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61746c646179732f6c61726176656c2d686173686964732e7376673f7374796c653d666f722d7468652d626164676526636f6c6f723d626c7565)](https://packagist.org/packages/atldays/laravel-hashids/stats)[![CI](https://camo.githubusercontent.com/e2df340bcc9d145a42104731dc89995c21111252b2b4a9a828aa96d2aa2f3b63/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f61746c646179732f6c61726176656c2d686173686964732f63692e796d6c3f7374796c653d666f722d7468652d6261646765266c6162656c3d4349)](https://github.com/atldays/laravel-hashids/actions/workflows/ci.yml)[![License: MIT](https://camo.githubusercontent.com/7a1226d14a365d288bfe51ece915ee0c7e754a16faa51ff06436504de29b33b4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e7376673f7374796c653d666f722d7468652d6261646765)](LICENSE.md)

`atldays/laravel-hashids` helps Laravel apps use hash IDs as one clean, consistent flow.

Instead of handling encoding, decoding, validation, routing and API output in different places, the package keeps everything working together:

- generating hash IDs on models
- resolving models from hash IDs
- route model binding
- validation rules
- request decoding in `FormRequest`
- serialized API output
- model-aware artisan commands

Under the hood, it is powered by [`hashids/hashids`](https://packagist.org/packages/hashids/hashids), while adding a Laravel-first developer experience around models, requests, validation and routing.

Your application can keep working with plain numeric values internally, while the outside world works with hash IDs in a predictable way.

Features
--------

[](#features)

- Model trait for generating and resolving hash IDs
- Query helpers like `findByHashId()` and `whereHashId()`
- Optional route model binding with hash IDs
- Validation rules for single and multiple values
- `FormRequest` integration for automatic decoding
- Wildcard request field support like `items.*.author`
- Optional serialized output that replaces the source column with a hash ID
- Model attributes for configuring hash ID source column and salt
- Legacy registry support for custom and old salts
- Artisan commands for model-specific encode and decode

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

[](#installation)

Install the package via Composer:

```
composer require atldays/laravel-hashids
```

Publish the config file if you want to customize the defaults:

```
php artisan vendor:publish --provider="Atldays\\HashIds\\HashIdServiceProvider" --tag="laravel-hashids-config"
```

If you plan to contribute, please also read [CONTRIBUTING.md](CONTRIBUTING.md).

Quick Start
-----------

[](#quick-start)

Add `HasHashId` to your model:

```
