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

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

bretterer/laravel-hashid
========================

Generate and use HashIds for your Laravel models, just like native ULIDs and UUIDs

v0.3.1(3mo ago)12.7k↑1233.3%[2 PRs](https://github.com/bretterer/laravel-hashid/pulls)MITPHPPHP ^8.3CI passing

Since Sep 18Pushed 1w agoCompare

[ Source](https://github.com/bretterer/laravel-hashid)[ Packagist](https://packagist.org/packages/bretterer/laravel-hashid)[ Docs](https://github.com/bretterer/laravel-hashid)[ GitHub Sponsors](https://github.com/bretterer)[ RSS](/packages/bretterer-laravel-hashid/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (6)Dependencies (22)Versions (13)Used By (0)

Laravel Hashid
==============

[](#laravel-hashid)

Generate and use HashIds for your Laravel models, just like native ULIDs and UUIDs.

[![Latest Version on Packagist](https://camo.githubusercontent.com/906b32fd969cd1ce146b5d39ad906174b62e4bf2d28ebefb5516186d0d21e298/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6272657474657265722f6c61726176656c2d6861736869642e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/906b32fd969cd1ce146b5d39ad906174b62e4bf2d28ebefb5516186d0d21e298/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6272657474657265722f6c61726176656c2d6861736869642e7376673f7374796c653d666c61742d737175617265)[![GitHub Tests Action Status](https://camo.githubusercontent.com/4ea785a4415d6f93984f9c8791ce078ca5f19b7329406d9124c699101791f3bd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6272657474657265722f6c61726176656c2d6861736869642f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/bretterer/laravel-hashid/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/8ba1132b13b3a307cbe146e45a685ad8b1e13e5fcf091f6af1557f173f5919f9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6272657474657265722f6c61726176656c2d6861736869642f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/bretterer/laravel-hashid/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/2ceee49bb2c3f2df8d60eeaeb0f1dc4b4e14721a594b0f7b2190607c41b09827/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6272657474657265722f6c61726176656c2d6861736869642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bretterer/laravel-hashid)

This package allows you to generate and use HashIds for your Laravel models, just like native ULIDs and UUIDs. It is easy to integrate and works seamlessly with Laravel's Eloquent models.

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

[](#installation)

Install via composer:

```
composer require bretterer/laravel-hashid
```

Usage
-----

[](#usage)

### 1. Add the Trait to Your Model

[](#1-add-the-trait-to-your-model)

```
use Bretterer\LaravelHashId\Traits\HasHashIds;

class User extends Model
{
	use HasHashIds;
	// ...
}
```

### 2. Use HashId Columns in Migrations

[](#2-use-hashid-columns-in-migrations)

```
Schema::create('users', function ($table) {
	$table->hashId('id', 16)->primary();
	$table->string('name');
});

Schema::create('posts', function ($table) {
	$table->hashId('id', 16)->primary();
	$table->foreignHashId('user_id', 'users', 'id', 16);
	$table->string('title');
});
```

### 3. Creating Models

[](#3-creating-models)

```
$user = User::create(['name' => 'Alice']);
echo $user->id; // 16-character base62 HashId

$post = Post::create(['user_id' => $user->id, 'title' => 'Hello']);
```

### 4. Custom Prefixes

[](#4-custom-prefixes)

```
class PrefixedUser extends Model {
	use HasHashIds;
	public function idPrefix(): string { return 'usr'; }
}

$user = PrefixedUser::create(['name' => 'Dave']);
echo $user->id; // usr_XXXXXXXXXXXXXXX
```

### 5. HashId Generator

[](#5-hashid-generator)

```
use Bretterer\LaravelHashId\LaravelHashId;

$generator = new LaravelHashId();
$hashId = $generator->generate(16); // Random HashId
$hashIdFromValue = $generator->generateFromValue('value', 'salt', 16); // HashId from value
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Brian Retterer](https://github.com/bretterer)
- [All Contributors](../../contributors)
- Special thanks to [Spatie](https://spatie.be/open-source) for their excellent Laravel package skeleton project.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance90

Actively maintained with recent releases

Popularity23

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.3% 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 ~37 days

Recently: every ~45 days

Total

6

Last Release

101d ago

### Community

Maintainers

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

---

Top Contributors

[![bretterer](https://avatars.githubusercontent.com/u/1906920?v=4)](https://github.com/bretterer "bretterer (17 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

laravellaravel-hashidbretterer

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

329530.5k29](/packages/codewithdennis-filament-select-tree)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

124603.0k](/packages/worksome-exchange)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.4k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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