PHPackages                             shabushabu/laravel-uid - 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. shabushabu/laravel-uid

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

shabushabu/laravel-uid
======================

v0.13.1(5d ago)4142MITPHPPHP ^8.2

Since Jul 1Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/ShabuShabu/laravel-uid)[ Packagist](https://packagist.org/packages/shabushabu/laravel-uid)[ Docs](https://github.com/ShabuShabu/laravel-uid)[ GitHub Sponsors](https://github.com/boris-glumpler)[ RSS](/packages/shabushabu-laravel-uid/feed)WikiDiscussions develop Synced 2d ago

READMEChangelogDependencies (32)Versions (21)Used By (0)

UIDs for Laravel
================

[](#uids-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2f77de68f1fab353f0e43253216bf8da85a0c23eaf2cf37ac1668ddad4a505a6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736861627573686162752f6c61726176656c2d7569642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/boris-glumpler/laravel-uid)[![Total Downloads](https://camo.githubusercontent.com/a3f748c110e44fd96b20289745aa147760e90cf7d86122063563890c5f3e26c0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736861627573686162752f6c61726176656c2d7569642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/boris-glumpler/laravel-uid)

Add Stripe-like universal ids to your models that can be decoded back to their integer ids.

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

[](#installation)

Caution

Please note that this is a new package and, even though it is well tested, it should be considered pre-release software

You can install the package via composer:

```
composer require shabushabu/laravel-uid
```

Publish the config file with:

```
php artisan vendor:publish --tag="uid-config"
```

### Prefixes

[](#prefixes)

You will then have to add all your models to the `prefixes` array in the config file:

```
return [
    // ...
    'prefixes' => [
        'usr' => \App\Models\User::class,
    ],
];
```

### Create a custom alphabet

[](#create-a-custom-alphabet)

Run the following command and add the output to your `.env` file:

```
php artisan uid:alphabet
```

Usage
-----

[](#usage)

The first step for every model should be to add the provided `HasUid` trait and the `Identifiable` interface. This also ensures that route model binding works as expected with UIDs.

```
use ShabuShabu\Uid\Concerns\HasUid;
use ShabuShabu\Uid\Contracts\Identifiable;

class User extends Model implements Identifiable
{
    use HasUid;
}
```

### Alphabets per model

[](#alphabets-per-model)

If you want to use custom alphabets for your models, you need to add them to the config file. Any model that does not use a custom alphabet will use the default alphabet.

```
return [
    // ...
    'alphabets' => [
        'usr' => 'abcdefgh...'
    ],
];
```

### Encode from an id

[](#encode-from-an-id)

```
use ShabuShabu\Uid\Service\Uid;

$uid = Uid::make()->encodeFromId(User::class, 1);

// something like: usr_86Rf07xd4z
```

### Encode a model

[](#encode-a-model)

```
use ShabuShabu\Uid\Facades\Uid;

// using the facade...
$uid = Uid::encode(User::find(1));

// something like: usr_86Rf07xd4z
```

### Decode a uid

[](#decode-a-uid)

```
// using the global function
$decoded = uid()->decode('usr_86Rf07xd4z');

// returns an instance of DecodedUid::class
```

### Decode to a model

[](#decode-to-a-model)

```
use ShabuShabu\Uid\Service\Uid;

$model = Uid::make()->decodeToModel('usr_86Rf07xd4z');

// returns an instance of User::class

$model = Uid::make()->withTrashed()->decodeToModel('usr_86Rf07xd4z');

// returns an instance of User::class, even if the model is trashed
```

### Check if a uid is valid

[](#check-if-a-uid-is-valid)

```
use ShabuShabu\Uid\Service\Uid;

$valid = Uid::make()->isValid('usr_86Rf07xd4z');

// returns true if the prefix exists

$valid = Uid::make()->isValid('usr_86Rf07xd4z', User::class);

// returns true if the prefix exists and belongs to the class
```

### Retrieve the alias of a given class

[](#retrieve-the-alias-of-a-given-class)

```
use ShabuShabu\Uid\Facades\Uid;

$alias = Uid::alias(User::class);

// returns usr
```

### Model info based on a UID

[](#model-info-based-on-a-uid)

If you have a UID and would like some info about it, then you can use the following command:

```
php artisan uid:info
```

### Using your prefixes as the morph map

[](#using-your-prefixes-as-the-morph-map)

You need to either set the `UID_MORPH_MAP_ENABLED` env variable to `true` or enable it directly in the config file.

By default, this will enable an enforced morph map, but you are free to change this to a regular one.

```
return [
    // ...
    'morph_map' => [
        'enabled' => true,
        'type' => 'regular',
    ],
];
```

### A word of warning

[](#a-word-of-warning)

Please note that this package does **not** work with string or compound primary keys. The underlying [Squids](https://github.com/sqids/sqids-php) library supports the encoding of an integer array, so compound primary keys might eventually be supported.

Validation
----------

[](#validation)

This package comes with its own validation rule that can be used like so:

```
use ShabuShabu\Uid\Service\Uid;

Uid::rule(User::class);
```

or

```
use ShabuShabu\Uid\Service\Rule;

new Rule(User::class);
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

Upgrade guide
-------------

[](#upgrade-guide)

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

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)

- [Squids](https://github.com/sqids/sqids-php)
- [ShabuShabu](https://github.com/ShabuShabu)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance88

Actively maintained with recent releases

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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 ~42 days

Recently: every ~85 days

Total

19

Last Release

5d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/31bd8ffbf4cfc6964e4bc0073b40d450e313c82d08c843b91899233be124ea71?d=identicon)[shabushabu](/maintainers/shabushabu)

---

Top Contributors

[![boris-glumpler](https://avatars.githubusercontent.com/u/580004?v=4)](https://github.com/boris-glumpler "boris-glumpler (77 commits)")

---

Tags

laravelshabushabularavel-uid

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/shabushabu-laravel-uid/health.svg)

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

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

13.0k107.5M1.6k](/packages/spatie-laravel-permission)[spatie/laravel-health

Monitor the health of a Laravel application

88212.7M185](/packages/spatie-laravel-health)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/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.

329575.9k33](/packages/codewithdennis-filament-select-tree)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5226.7k](/packages/simplestats-io-laravel-client)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3915.5k](/packages/rawilk-profile-filament-plugin)

PHPackages © 2026

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