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

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

laragrad/uuid
=============

Custom UUID generate and analyze functions

v1.2.1(3y ago)042312MITPHPPHP ^7.2|^8.0

Since Oct 7Pushed 3y ago1 watchersCompare

[ Source](https://github.com/laragrad/uuid)[ Packagist](https://packagist.org/packages/laragrad/uuid)[ RSS](/packages/laragrad-uuid/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (5)Dependencies (1)Versions (7)Used By (2)

laragrad/uuid
=============

[](#laragraduuid)

Package provides any functions to generate and analyze UUID with special structure.

There used special 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

The application code and the object code are integer values that are packed into the generated UUID. These codes allow you to identify (programmatically or even visually) the entity and application for which the UUID was generated. Also, a UUID generation timestamp is packed into the UUID with an accuracy of microseconds.

Installing
----------

[](#installing)

To install a package run command:

```
composer require laragrad/uuid

```

Using trait HasUuidPrimaryKey
-----------------------------

[](#using-trait-hasuuidprimarykey)

Use trait `/Laragrad/Uuid/Models/Concerns/HasUuidPrimaryKey` in your model where required UUID primary key.

Declare public properties `$appCode` and `$entityCode` in your model to tune uuid generating.

Trait overwrites `getIncrementing()` and `getKeyType()` methods. You must not to fill properties `$incrementing` and `$keyType` in the model.

Trait registers model event handler for **creating**-event to generating UUID and filling model key.

Example:

```
use /Laragrad/Uuid/Models/Concerns/HasUuidPrimaryKey;

class MyModel extends Model
{
	use HasUuidPrimaryKey

	public $appCode = 0x002;

	public $entityCode = 0x000F;

}
```

Helper functions
----------------

[](#helper-functions)

### gen\_uuid()

[](#gen_uuid)

Use gen\_uuid() to generate uuid.

Syntax:

```
gen_uuid( [[int $entityCode] , int $appCode] ) : string

```

Arguments:

- `$entityCode` - integer entity code (default - 0) in range from 0 to 65535
- `$appCode` - integer application code (default - 0) in range from 0 to 4095

Returning: Generated UUID as string.

```
$uuid = gen_uuid(0xF,0x2);
echo $uuid; // 622235ea-8e54-f002-000f-742c8deebf77
```

### get\_uuid\_timestamp()

[](#get_uuid_timestamp)

Extracts timestamp from uuid generated by **gen\_uuid()**.

Syntax:

```
get_uuid_timestamp( string $uuid [, string $format] ) : mixed

```

Arguments:

- `$uuid` - analyzed UUID;
- `$format` - returning value format:
    - `Carbon` (default) \\Carbon\\Carbon;
    - `DateTime` \\DateTime object;
    - format string to return formatted data string. Example: `'Y-m-d H:i:s.u'`

Returning: \\Carbon\\Carbon | \\DateTime | string.

Example:

```
$uuid = gen_uuid(0xF,0x2);
echo get_uuid_timestamp($uuid', 'Y-m-d H:i:s.u');
// 2022-03-04 19:00:39.906514
```

### get\_uuid\_app\_code()

[](#get_uuid_app_code)

Extracts application code from uuid generated by **gen\_uuid()**.

Syntax:

```
get_uuid_app_code( string $uuid ) : string

```

Arguments:

- `$uuid` - analyzed UUID;

Example:

```
$uuid = gen_uuid(0xF,0x2);
echo get_uuid_app_code($uuid');
// 2
```

### get\_uuid\_entity\_code()

[](#get_uuid_entity_code)

Extracts entity code from uuid generated by **gen\_uuid()**.

Syntax:

```
get_uuid_entity_code( string $uuid ) : string

```

Arguments:

- `$uuid` - analyzed UUID;

Example:

```
$uuid = gen_uuid(0xF,0x2);
echo get_uuid_entity_code($uuid');
// 15
```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity64

Established project with proven stability

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

Total

5

Last Release

1458d ago

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

v1.1PHP ^7.2|^8.0

### Community

Maintainers

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

---

Top Contributors

[![laragrad](https://avatars.githubusercontent.com/u/65588602?v=4)](https://github.com/laragrad "laragrad (5 commits)")

---

Tags

laraveluuid

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/laragrad-uuid/health.svg)](https://phpackages.com/packages/laragrad-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.3k18](/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)
