PHPackages                             evo-mark/laravel-id-obfuscator - 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. evo-mark/laravel-id-obfuscator

ActiveLibrary[Security](/categories/security)

evo-mark/laravel-id-obfuscator
==============================

Obfuscate your IDs when sending them to the frontend

1.5.0(2mo ago)44.8k↓32%2MITPHPPHP ^8.1

Since Sep 24Pushed 11mo ago3 watchersCompare

[ Source](https://github.com/evo-mark/laravel-id-obfuscator)[ Packagist](https://packagist.org/packages/evo-mark/laravel-id-obfuscator)[ Docs](https://github.com/evo-mark/laravel-id-obfuscator)[ RSS](/packages/evo-mark-laravel-id-obfuscator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (10)Versions (11)Used By (0)

 [    ![evoMark company logo](https://camo.githubusercontent.com/0ee00c831e18d82e5d32990e52b0b08b13c97ff2374478eef348c17bd3485c3c/68747470733a2f2f65766f6d61726b2e636f2e756b2f77702d636f6e74656e742f75706c6f6164732f7374617469632f65766f6d61726b2d6c6f676f2d2d6c696768742e737667)  ](https://evomark.co.uk)

 [![Build status](https://camo.githubusercontent.com/c1d8e07c144c7a9b9fb4914ccb8d165902b24e17669f3fe787ea0dcfd2f66454/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f65766f2d6d61726b2f6c61726176656c2d69642d6f626675736361746f723f6c6f676f3d7061636b6167697374266c6f676f436f6c6f723d7768697465)](https://packagist.org/packages/evo-mark/laravel-id-obfuscator) [![Total Downloads](https://camo.githubusercontent.com/86f1a4853388f80ac658ac4b17e51ff8feeab260609b835770c43bf70dbafb17/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f65766f2d6d61726b2f6c61726176656c2d69642d6f626675736361746f72)](https://packagist.org/packages/evo-mark/laravel-id-obfuscator) [![Licence](https://camo.githubusercontent.com/a79e3e822bd9583d05be5acadcf76dc3cfea210ad584397b2a73571bcb49eea6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f65766f2d6d61726b2f6c61726176656c2d69642d6f626675736361746f72)](https://packagist.org/packages/evo-mark/laravel-id-obfuscator)

Laravel ID Obfuscator
=====================

[](#laravel-id-obfuscator)

Incrementing primary keys may reveal more than you wish in a public-facing application. Order IDs can reveal your sales volume to competitors and User IDs can invite enumeration attacks.

This package implements a two-way hashing on `Obfuscatable` models and converts an ID of, say, `7` into an ID of `fh38aj2e` when it travels to the frontend and converts it back on return.

> Warning: This package only obfuscates IDs and should not be used if secure encryption of identifiers is required

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

[](#installation)

```
composer require evo-mark/laravel-id-obfuscator
```

Models
------

[](#models)

### Usage

[](#usage)

```
use EvoMark\LaravelIdObfuscator\Traits\Obfuscatable;

class User extends Authenticatable
{
    use Obfuscatable;
}
```

Using the `Obfuscatable` trait provides automatic route model binding with decoding and then automatic encoding when the primary key is sent to the frontend

```
Route::get('/users/{user}', [SomeController::class, 'index']);

// SomeController

public function index(User $user)
{
    // $user will now have the decoded ID ready for internal use

    // If you need to access the obfuscated ID internally, you can use
    $obfuscatedId = $user->obfuscatedId;
}
```

`Obfuscatable` models will also feature automatic decoding when using the model's `find`-style functions: e.g. `find`, `findOrFail`, `findMany`, `findOrNew`, `findOr`

```
// SomeController

/**
 * @param string $id The obfuscated order ID
 */
public function index($id)
{
    $order = Order::find($id);
}
```

Validation
----------

[](#validation)

**Laravel ID Obfuscator** comes with a built-in rule extension for validating incoming obfuscated ids, simply:

```
public function store($request)
{
    $validated = $request->validate([
        'id' => ['required','id_exists:users']
    ]);
}
```

Facade
------

[](#facade)

You can access the encoding and decoding features anytime via the provided facade.

```
use EvoMark\LaravelIdObfuscator\Facades\Obfuscate;

$encoded = Obfuscate::encode(5);
$decoded = Obfuscate::decode($encoded);
```

toArray
-------

[](#toarray)

Primary keys on Obfuscated models will automatically be obfuscated when sending models to the frontend.

If you want to encode foreign keys on the model as well, enable the `encodeForeign` setting in your `obfuscator` config.

Config
------

[](#config)

You can publish the package config by running the following Artisan command:

```
php artisan v:p --provider="EvoMark\LaravelIdObfuscator\Provider"
```

SettingTypeDefaultDescriptionseedstringlaravel-id-obfuscatorA seed string for the encoderlengthint8The amount of chars to pad the output toalphabet.string\[a-zA-Z0-9\] (as string)The alphabet to use when encoding IDsencodeForeignboolfalseEncode obfuscated foreign keys too.Q &amp; A
---------

[](#q--a)

1. Why not use UUIDs?

- UUIDs can be [Bad for database performance](https://www.danielfullstack.com/article/stop-using-uuids-in-your-database), whereas this obfuscation only runs when data bridges between the backend and the frontend of your application.

Limitations
-----------

[](#limitations)

- Laravel ID Obfuscator can only be used on incrementing primary keys
- Since this package overrides the `newEloquentBuilder` method on obfuscated models, it is incompatible with any other packages that also do the same. Some examples might include:
    - [mikebronner/laravel-model-caching](https://github.com/mikebronner/laravel-model-caching)
    - [grimzy/laravel-mysql-spatial](https://github.com/grimzy/laravel-mysql-spatial)
    - [fico7489/laravel-pivot](https://github.com/fico7489/laravel-pivot)
    - [spatie/laravel-query-builder](https://github.com/spatie/laravel-query-builder)
    - [dwightwatson/rememberable](https://github.com/dwightwatson/rememberable)
    - [chelout/laravel-relationship-events](https://github.com/chelout/laravel-relationship-events)
    - [lazychaser/laravel-nestedset](https://github.com/lazychaser/laravel-nestedset)

Support Open-Source Software
----------------------------

[](#support-open-source-software)

We're providing this community adapter free-of-charge without any paywalled features. However, all development and maintenance costs time, energy and money. So please help fund this project if you can.

[![](https://camo.githubusercontent.com/e196e128a01f6cfb1d468f663d20df05e2255ba345df79f5e343e78fb753a673/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73706f6e736f722d47697448756225323053706f6e736f72732d6661666266633f7374796c653d666f722d7468652d6261646765266c6f676f3d676974687562)](https://github.com/sponsors/craigrileyuk)[![Buy Me A Coffee](https://camo.githubusercontent.com/0cf29a542375e1a46e84d8bf5805a4e5c0a6ee98b6547ccdc0c55eed49d99c69/68747470733a2f2f63646e2e6275796d6561636f666665652e636f6d2f627574746f6e732f76322f64656661756c742d79656c6c6f772e706e67)](https://www.buymeacoffee.com/craigrileyuk)

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance67

Regular maintenance activity

Popularity29

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

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

Recently: every ~119 days

Total

10

Last Release

60d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4f42ee39ec10e8f4b3552a78ea78628acef13e9772bed852baa186e97bde7748?d=identicon)[evomark](/maintainers/evomark)

---

Top Contributors

[![craigrileyuk](https://avatars.githubusercontent.com/u/68274157?v=4)](https://github.com/craigrileyuk "craigrileyuk (8 commits)")[![thecoopertempleclause](https://avatars.githubusercontent.com/u/71491231?v=4)](https://github.com/thecoopertempleclause "thecoopertempleclause (3 commits)")[![wRWebDev](https://avatars.githubusercontent.com/u/72814982?v=4)](https://github.com/wRWebDev "wRWebDev (2 commits)")[![YonkoSam](https://avatars.githubusercontent.com/u/161728760?v=4)](https://github.com/YonkoSam "YonkoSam (1 commits)")

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/evo-mark-laravel-id-obfuscator/health.svg)

```
[![Health](https://phpackages.com/badges/evo-mark-laravel-id-obfuscator/health.svg)](https://phpackages.com/packages/evo-mark-laravel-id-obfuscator)
```

###  Alternatives

[illuminate/encryption

The Illuminate Encryption package.

9229.7M280](/packages/illuminate-encryption)[tzsk/otp

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

241641.4k1](/packages/tzsk-otp)[genealabs/laravel-governor

Managing policy and control in Laravel.

201262.8k](/packages/genealabs-laravel-governor)[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)[laragear/poke

Keep your forms alive, avoid TokenMismatchException by gently poking your Laravel app

2211.5k](/packages/laragear-poke)

PHPackages © 2026

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