PHPackages                             limanweb/uuid - 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. limanweb/uuid

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

limanweb/uuid
=============

Custom UUID generate and analyze functions

v1.1.1(2y ago)15.1k↓66.7%MITPHPPHP ^7.2.0|^8.0

Since May 16Pushed 2y ago1 watchersCompare

[ Source](https://github.com/limanweb/uuid)[ Packagist](https://packagist.org/packages/limanweb/uuid)[ RSS](/packages/limanweb-uuid/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

limanweb/uuid
=============

[](#limanwebuuid)

Description
-----------

[](#description)

Package provides any functions to generate and analyze UUID.

### Structure of generated UUID

[](#structure-of-generated-uuid)

There used custom algorithm to generate UUID with next structure:

```
SSSSSSSS-UUUU-UAAA-EEEE-RRRRRRRRRRRR

```

- `S` - 8 hex digits is seconds value of UUID generating timestamp
- `U` - 5 hex digits is microseconds value of UUID generating timestamp
- `A` - 3 hex digits is custom application code
- `E` - 4 hex digits is custom entity code
- `R` - 12 hex digits is random value

### What is entity and application codes?

[](#what-is-entity-and-application-codes)

You can define any integer entity code and/or application code when call genUuid(). This allows you to distinguish visually and programmatically between UUIDs created by different applications for different DB entities.

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

[](#installation)

Run command to install a package into you project

```
composer require limanweb/uuid

```

Limanweb\\Uuid\\Support\\Uuid functions
---------------------------------------

[](#limanwebuuidsupportuuid-functions)

### genUuid()

[](#genuuid)

Syntax:

```
genUuid(int $entityCode = null, int $appCode = null) : string

```

Returns UUID-string.

Params:

- `$entityCode` - custom integer code of entity (is 0 by default). Max value is 65535
- `$appCode` - custom integer code of application (is 0 by default). Max value is 4095

Returns UUID string.

Example:

```
$uuid = \Limanweb\Uuid\Support\Uuid::genUuid(256, 16);
echo $uuid; // "5ec004c4-0db2-0010-0100-a08cc1dd9a2b"
```

### getUuidTimestamp()

[](#getuuidtimestamp)

Syntax:

```
getUuidTimestamp(string $uuid, string $format = 'Carbon') : mixed

```

Retrieve timestamp from UUID generated by `genUuid()`.

Params:

- `$uuid` - analyzed UUID;
- `$format` - format of returning timestamp value. You can use one of tree variants:
    - `Carbon` (default) to get timestamp as \\Carbon\\Carbon object;
    - `DateTime` to get timestamp as \\DateTime object;
    - date format string used for `format()` to get timestamp as formatted string. For example: `'Y-m-d H:i:s.u'`

Example:

```
$uuid = "5ec004c4-0db2-0010-0100-a08cc1dd9a2b";

$ts = \Limanweb\Uuid\Support\Uuid::getUuidTimestamp($uuid, "Y-m-d H:i:s.u");

echo $ts; // "2020-05-16 18:20:36.056096"
```

### getUuidAppCode()

[](#getuuidappcode)

Syntax:

```
getUuidAppCode(string $uuid) : int

```

Retrieve application code from UUID generated by `genUuid()`.

Params:

- `$uuid` - analyzed UUID;

Example:

```
$uuid = "5ec004c4-0db2-0010-0100-a08cc1dd9a2b";

$appCode = \Limanweb\Uuid\Support\Uuid::getUuidAppCode($uuid);
echo $appCode; // 16
```

### getUuidAppCode()

[](#getuuidappcode-1)

Syntax:

```
getUuidAppCode(string $uuid) : int

```

Retrieve application code from UUID generated by `genUuid()`.

Params:

- `$uuid` - analyzed UUID;

Example:

```
$uuid = "5ec004c4-0db2-0010-0100-a08cc1dd9a2b";

$appCode = \Limanweb\Uuid\Support\Uuid::getUuidAppCode($uuid);
echo $appCode; // 256
```

Using trait UsesUuid
--------------------

[](#using-trait-usesuuid)

1. Add trait `\Limanweb\Uuid\Models\Concerns\UsesUuids` use declaration into models where primary key is UUID.
2. You can define `$appCode` and `$entityCode` protected properties in your model to generate model UUID-key with specific segments.

This trait

- overrides `getIncrementing()` and `getKeyType()` methods therefore you don't need to define properties `$incrementing` and `$keyType`;
- adds `getAppCode()` and `getEntityCode()` public methods;
- registers **creating** event handler to generate UUID and fill model key.

Example:

```
class MyModel extends Model
{
	use \Limanweb\Uuid\Models\Concerns\UsesUuids;

	protected $appCode = 16;	// 010
	protected $entityCode = 256;	// 0100

	...
```

All IDs generated for this model will match the pattern `########-####-#010-0100-############`.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 63.6% 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 ~491 days

Total

4

Last Release

767d ago

PHP version history (2 changes)v1.0PHP ^7.2.0

v1.1.1PHP ^7.2.0|^8.0

### Community

Maintainers

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

---

Top Contributors

[![limanweb](https://avatars.githubusercontent.com/u/17918827?v=4)](https://github.com/limanweb "limanweb (7 commits)")[![ocs-laravel](https://avatars.githubusercontent.com/u/72538616?v=4)](https://github.com/ocs-laravel "ocs-laravel (4 commits)")

---

Tags

laraveluuid

### Embed Badge

![Health badge](/badges/limanweb-uuid/health.svg)

```
[![Health](https://phpackages.com/badges/limanweb-uuid/health.svg)](https://phpackages.com/packages/limanweb-uuid)
```

###  Alternatives

[illuminate/support

The Illuminate Support package.

630113.0M41.3k](/packages/illuminate-support)[solspace/craft-freeform

The most flexible and user-friendly form building plugin!

54681.3k19](/packages/solspace-craft-freeform)[erlandmuchasaj/laravel-gzip

Gzip your responses.

40146.5k2](/packages/erlandmuchasaj-laravel-gzip)[japanese-date/japanese-date

日本の暦、祝日を取り扱うライブラリ

1610.0k](/packages/japanese-date-japanese-date)

PHPackages © 2026

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