PHPackages                             swindon/filament-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. [Security](/categories/security)
4. /
5. swindon/filament-hashids

ActiveLibrary[Security](/categories/security)

swindon/filament-hashids
========================

A Laravel Filament package that automatically encodes and decodes model IDs using vinkla/hashids for improved security and aesthetics.

v1.0.0(1y ago)3286MITPHPPHP ^8.0

Since Apr 2Pushed 1y ago1 watchersCompare

[ Source](https://github.com/swindon/filament-hashids)[ Packagist](https://packagist.org/packages/swindon/filament-hashids)[ RSS](/packages/swindon-filament-hashids/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Filament Hashids
================

[](#filament-hashids)

Filament Hashids is a Laravel package that automatically encodes and decodes model IDs using [vinkla/hashids](https://github.com/vinkla/hashids). By replacing numerical IDs with obfuscated Hashids, this package not only improves the aesthetics of your URLs but also provides an extra layer of security.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Using the Model Trait](#using-the-model-trait)
    - [Blade Directive](#blade-directive)
    - [Setup the Middleware](#setup-the-middleware)
- [Testing](#testing)
- [Contributing](#contributing)
- [Licence](#licence)

Features
--------

[](#features)

- **Automatic Hashid Encoding**: Transform model IDs in your URLs (e.g. `/admin/users/1/edit` becomes `/admin/users/0l8q7xpnm4k63jo9/edit`).
- **Automatic Hashid Decoding**: Middleware decodes Hashids back to real IDs when processing requests.
- **Model Trait (`HasHashid`)**: Easily apply Hashids to any Filament model.
- **Filament Plugin (`HashidsPlugin.php`)**: Seamlessly integrate with Filament, overriding resource routes and actions.
- **Customisable Hashid Config**: Configure custom salts, minimum length, and alphabet via `filament-hashids.php`.
- **Blade Directive (`@hashid($model)`)**: Helper directive for generating Hashids in your Blade templates.
- **Artisan Command (`install:hashids`)**: Simplifies setup by publishing configuration files and verifying dependencies.

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

[](#installation)

Install the package via Composer:

```
composer require swindon/filament-hashids
```

If you wish to customise the configuration, run the install command:

```
php artisan install:filament-hashids
```

This command will publish the configuration file (`config/filament-hashids.php`) to your Laravel application.

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

[](#configuration)

After installation, you can adjust your settings in the `config/filament-hashids.php` file. You may set:

- **salt**: A custom salt value (defaults to your `APP_KEY`).
- **min\_length**: The minimum length for the generated Hashid.
- **alphabet**: The alphabet used to generate the Hashid.

Usage
-----

[](#usage)

### Using the Model Trait

[](#using-the-model-trait)

Simply include the `HasHashid` trait in your model to enable Hashid functionality:

```
use Swindon\FilamentHashids\Traits\HasHashid;

class User extends Authenticatable
{
    use HasHashid;

    // ...
}
```

You can then retrieve the Hashid for a model instance:

```
$user = User::find(1);
echo $user->getHashid();
```

You can query by Hashid for a model:

```
$user = User::findHashId($hashId);
$users = User::whereHashId($hashId)->get();
```

### Blade Directive

[](#blade-directive)

In your Blade templates, generate a Hashid easily with the provided directive:

```
@hashid($user)
```

This will output the encoded ID of the model.

### Setup the Middleware

[](#setup-the-middleware)

Middleware ensures that incoming requests with Hashids are automatically decoded into their corresponding numerical IDs. You can set it up in two ways:

#### Via Panels

[](#via-panels)

To apply the middleware globally to a Filament panel, include it in the panel's middleware stack:

```
use Filament\Panel;
use Filament\PanelProvider;
use Swindon\FilamentHashids\Middleware\FilamentHashidsMiddleware;

class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->middleware([
                FilamentHashidsMiddleware::class, // Decodes Hashids for all routes in this panel
                // ...existing code...
            ]);
    }
}
```

#### Via Specific Resources

[](#via-specific-resources)

If you want to apply the middleware to specific resources only, you can define it in the resource's `$routeMiddleware` property:

```
use Filament\Resources\Resource;

class UserResource extends Resource
{
    public static array|string $routeMiddleware = [
        'filament-hashids', // Ensures Hashids are decoded for this resource's routes
    ];
}
```

Testing
-------

[](#testing)

The package includes a suite of tests to cover its key functionality:

- **Feature Tests**: Validate that URLs are correctly rewritten and that routes work as expected.
- **Unit Tests**: Ensure that the `HashidsManager`, middleware, and helper functions behave correctly.

To run the tests, simply execute:

```
vendor/bin/phpunit
```

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

[](#contributing)

Contributions are welcome! Feel free to open issues or submit pull requests if you have suggestions or improvements.

Licence
-------

[](#licence)

This package is open-sourced software licensed under the [MIT licence](LICENSE).

---

Enjoy building secure and aesthetically pleasing URLs with Filament Hashids!

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance46

Moderate activity, may be stable

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

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

Unknown

Total

1

Last Release

411d ago

### Community

Maintainers

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

---

Top Contributors

[![swindon](https://avatars.githubusercontent.com/u/7947471?v=4)](https://github.com/swindon "swindon (10 commits)")

---

Tags

urllaravelsecurityencodinghashidsfilament

### Embed Badge

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

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

###  Alternatives

[tzsk/otp

A secure, database-free One-Time Password (OTP) generator and verifier for PHP and Laravel.

241641.4k1](/packages/tzsk-otp)[dgtlss/warden

A Laravel package that proactively monitors your dependencies for security vulnerabilities by running automated composer audits and sending notifications via webhooks and email

8745.6k](/packages/dgtlss-warden)[ercsctt/laravel-file-encryption

Secure file encryption and decryption for Laravel applications

642.6k](/packages/ercsctt-laravel-file-encryption)

PHPackages © 2026

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