PHPackages                             swiss-devjoy/laravel-easy-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. swiss-devjoy/laravel-easy-hashids

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

swiss-devjoy/laravel-easy-hashids
=================================

Easy HashIds for Laravel Eloquent models with Livewire Support

v1.2.0(4mo ago)21.8kMITPHPPHP ^8.2CI passing

Since Apr 18Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/swiss-devjoy/laravel-easy-hashids)[ Packagist](https://packagist.org/packages/swiss-devjoy/laravel-easy-hashids)[ Docs](https://github.com/swiss-devjoy/laravel-easy-hashids)[ GitHub Sponsors](https://github.com/sponsors/swiss-devjoy)[ RSS](/packages/swiss-devjoy-laravel-easy-hashids/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (15)Versions (4)Used By (0)

Easy HashIds for Laravel Eloquent Models with Livewire Support
==============================================================

[](#easy-hashids-for-laravel-eloquent-models-with-livewire-support)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ab13f0361de6fc587f08cc660f70a0a1269a45863eaf406552cce2c3e6d37283/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73776973732d6465766a6f792f6c61726176656c2d656173792d686173686964732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/swiss-devjoy/laravel-easy-hashids)[![Total Downloads](https://camo.githubusercontent.com/0760810a805853c56968f0648e03614e4f452a2a403cd1e87c1bcf46faaff2e8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73776973732d6465766a6f792f6c61726176656c2d656173792d686173686964732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/swiss-devjoy/laravel-easy-hashids)

A lightweight package that adds Hashid support to your Eloquent models. It automatically generates unique hashids for your models and includes Livewire support for only exposing the hashid as key to properly identify a public model.

Why Use HashIds?
----------------

[](#why-use-hashids)

- **Security by Obscurity**: Hide your sequential database IDs from users (although is not an encryption library)
- **Predictability Prevention**: Avoid exposing information about your data volume
- **Performance**: Invalid hashids don't lead to unnecessary database fetches (in most cases)

Features
--------

[](#features)

- ✅ Easy integration with any Eloquent model
- ✅ Automatic hashid generation based on model IDs
- ✅ Livewire component support for passing models with hashids
- ✅ Route model binding support
- ✅ Auto generation of different hashids for different models, even if the ID is the same
- ✅ Configurable alphabet and minimum length globally and per model
- ✅ No database migrations needed - works with your existing models

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

[](#installation)

You can install the package via composer:

```
composer require swiss-devjoy/laravel-easy-hashids

```

You can publish the config file with:

```
php artisan vendor:publish --tag="laravel-easy-hashids-config"

```

This is the contents of the published config file:

```
return [
    'default' => [
        // Generate a unique alphabet here: https://sqids.org/playground
        'alphabet' => env('HASHID_DEFAULT_ALPHABET', 'VCzODgjZNMFaXTfqnhLp84EtHlk7RmiWrScBoPIwK2QGxs1ed35UJ6yAYb0v9u'),
        'min_length' => env('HASHID_DEFAULT_MIN_LENGTH', 10),
    ],

    'models' => [
        // App\Models\YourModel::class => [
        //     'alphabet' => 'kwevdSQOEiT349X5atVrLozGHFWYp87uAUlc0mbPNIJKf1qMshCyg2BD6ZxnjR',
        //     'min_length' => 10,
        // ],
    ],
];

```

Usage
-----

[](#usage)

1. Add the `HasHashid` and `HashidRouting` traits to any Eloquent model:

```
use SwissDevjoy\LaravelEasyHashids\HasHashid;
use SwissDevjoy\LaravelEasyHashids\HashidRouting;

class Product extends Model
{
    use HasHashid;
    use HashidRouting;
}

```

2. Access the hashid in your code:

```
$product = Product::find(1);
echo $product->hashid; // Returns something like "2tFub5I1ge"

```

3. Use route model binding with hashids:

```
Route::get('/products/{product}', function (Product $product) {
    return view('products.show', compact('product'));
})->name('products.product');

// Generates a URL with the hashid that looks sth like /products/2tFub5I1ge
route('products.show', ['product' => $product]);

```

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

[](#configuration)

The published config file contains these settings:

```
return [
    'default' => [
        // Generate a unique alphabet here: https://sqids.org/playground
        'alphabet' => env('HASHID_DEFAULT_ALPHABET', 'VCzODgjZNMFaXTfqnhLp84EtHlk7RmiWrScBoPIwK2QGxs1ed35UJ6yAYb0v9u'),
        'min_length' => env('HASHID_DEFAULT_MIN_LENGTH', 10),
    ],

    'models' => [
        // App\Models\YourModel::class => [
        //     'alphabet' => 'kwevdSQOEiT349X5atVrLozGHFWYp87uAUlc0mbPNIJKf1qMshCyg2BD6ZxnjR',
        //     'min_length' => 10,
        // ],
    ],
];

```

### Working with Livewire

[](#working-with-livewire)

The package automatically handles Livewire integration. When passing models with the `HasHashid` trait to Livewire components, their IDs will be converted to hashids:

```
class BookComponent extends Component
{
    public Book $book;

    public function render()
    {
        return view('components.book');
    }
}

```

The model will be automatically serialized with the hashid and reconstituted when needed.

### Converting Between IDs and HashIds

[](#converting-between-ids-and-hashids)

You can manually convert between IDs and hashids:

```
$book = Book::make();

// Convert ID to hashid
$hashid = $book->idToHashid(10);

// Convert hashid back to ID
$id = $book->hashidToId('2tFub5I1ge');

```

### Relationships

[](#relationships)

The package works seamlessly with Eloquent relationships:

```
// Author model (uses HasHashid)
$author = Author::findByHashidOrFail('uwe14hrgh');

// Book model (uses HasHashid)
$book = $author->books()->findByHashid('2tFub5I1ge');

```

Advanced Configuration
----------------------

[](#advanced-configuration)

### Model-Specific Settings

[](#model-specific-settings)

You can customize the alphabet and minimum hashid length for specific models in the config file:

```
'models' => [
    App\Models\Book::class => [
        'alphabet' => 'xyz123ABC789DEFGHIJKLMNOPQRSTUVWdefghijklmnopqrstuvwab456XYZ',
        'min_length' => 12,
    ],
],

```

### Auto-Generated Alphabets

[](#auto-generated-alphabets)

If no custom configuration is provided, the package will generate a unique alphabet for each model based on the class name. This ensures distinct hashids across different models even for identical database IDs.

For example, `User::find(1)->hashid` will be different from `Product::find(1)->hashid`.

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)

- [Dimitri König](https://github.com/dimitri-koenig)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance77

Regular maintenance activity

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~132 days

Total

3

Last Release

124d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/94ba6c20d1e53a2066e9df02d8fe50390629cc344e16531f552c843c32032180?d=identicon)[dimitri-koenig](/maintainers/dimitri-koenig)

---

Top Contributors

[![dimitri-koenig](https://avatars.githubusercontent.com/u/4375825?v=4)](https://github.com/dimitri-koenig "dimitri-koenig (5 commits)")

---

Tags

hashidslaravellivewirephpsqidslaraveldevjoy.chlaravel-easy-hashids

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/swiss-devjoy-laravel-easy-hashids/health.svg)

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

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.7k28.9M627](/packages/spatie-laravel-data)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)

PHPackages © 2026

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