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

ActiveLibrary

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

v0.13.0(2mo ago)3123↓100%MITPHPPHP ^8.2

Since Jul 1Pushed 2mo 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 today

READMEChangelogDependencies (16)Versions (20)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

42

—

FairBetter than 90% of packages

Maintenance86

Actively maintained with recent releases

Popularity15

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

Total

18

Last Release

67d 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 (75 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

[orptech/laravel-migration-partition

Laravel extensions that extends Illuminate to enable partitioned table creation within Laravel migrations.

3426.1k](/packages/orptech-laravel-migration-partition)

PHPackages © 2026

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