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

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

novay/laravel-uuid
==================

Laravel package to generate and to validate a UUID according to the RFC 4122 standard. UUID Versions 1, 3, 4 and 5 are supported.

v3.0(8y ago)0103MITPHPPHP &gt;=7.0.0

Since Jan 28Pushed 8y ago1 watchersCompare

[ Source](https://github.com/novay/laravel-uuid)[ Packagist](https://packagist.org/packages/novay/laravel-uuid)[ Docs](https://github.com/novay/laravel-uuid)[ RSS](/packages/novay-laravel-uuid/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Laravel UUID (Universally Unique Identifier)
============================================

[](#laravel-uuid-universally-unique-identifier)

[![Total Downloads](https://camo.githubusercontent.com/953359ba735f2da6ff5cde158451d78c2530212fe9c83a78e496078c69fc833f/68747470733a2f2f706f7365722e707567782e6f72672f6e6f7661792f6c61726176656c2d757569642f642f746f74616c2e737667)](https://packagist.org/packages/novay/laravel-uuid)[![Build Status](https://camo.githubusercontent.com/60e155bb8ecca6bf8ad83362012d86217eac8ed5179561a566667cd3217a2cd1/68747470733a2f2f7472617669732d63692e6f72672f6e6f7661792f6c61726176656c2d757569642e7376673f6272616e63683d6d6173746572)](http://travis-ci.org/novay/laravel-uuid)[![Latest Stable Version](https://camo.githubusercontent.com/ed62f46cab76c8a159889d1fe54c39d617d4ed7e961a72cce4f5241fd4802573/68747470733a2f2f706f7365722e707567782e6f72672f6e6f7661792f6c61726176656c2d757569642f762f737461626c652e737667)](https://packagist.org/packages/novay/laravel-uuid)[![Latest Unstable Version](https://camo.githubusercontent.com/764d17677bce3d0b391ce0e6125a1feb344aca5f6cfa345bf1d780e7a558c67e/68747470733a2f2f706f7365722e707567782e6f72672f6e6f7661792f6c61726176656c2d757569642f762f756e737461626c652e737667)](https://packagist.org/packages/novay/laravel-uuid)[![License](https://camo.githubusercontent.com/4a63502acf4868abb6625d22126dfc3ea59af5d9cb894ba62e84b63a5242460c/68747470733a2f2f706f7365722e707567782e6f72672f6e6f7661792f6c61726176656c2d757569642f6c6963656e73652e737667)](https://raw.githubusercontent.com/novay/laravel-auth/LICENSE)

Laravel package to generate a UUID according to the RFC 4122 standard. UUID Versions 1, 3, 4 and 5 are supported. With MIT license.

- [About](#about)
- [Requirements](#requirements)
- [Installation](#installation)
    - [Laravel 5.5 and above](#laravel-5.5-and-above)
    - [Laravel 5.4 and below](#laravel-5.4-and-below)
- [Basic Usage](#basic-usage)
- [Advanced Usage](#advanced-usage)
    - [UUID creation](#uuid-creation)
        - [UUID V1](#uuid-v1)
        - [UUID V3](#uuid-v3)
        - [UUID V4](#uuid-v4)
        - [UUID V5](#uuid-v5)
- [Additional Features](#additional-features)
    - [Import UUID](#import-uuid)
    - [Extract time](#extract-time)
    - [Extract Version](#extract-version)
    - [Eloquent UUID Generation](#eloquent-uuid-generation)
    - [Model Binding to UUID instead of Primary Key](#model-binding-to-uuid-instead-of-primary-key)
    - [Validation](#validation)
- [License](#license)
- [Notes](#notes)
- [Credits](#credits)

### About

[](#about)

Since Laravel `4.*` and `5.*` both rely on either `OpenSSL` or `Mcrypt`, the pseudo random byte generator now tries to use one of them. If both cannot be used (not a Laravel project?), the 'less random' `mt_rand()` function is used.

### Requirements

[](#requirements)

- [Laravel 5.3, 5.4 or 5.5+](https://laravel.com/docs/installation)

### Installation

[](#installation)

##### Laravel 5.5 and above

[](#laravel-55-and-above)

1. From your projects root folder in terminal run:

```
    composer require novay/laravel-uuid
```

- Uses package auto discovery feature, no need to edit the `config/app.php` file.

##### Laravel 5.4 and below

[](#laravel-54-and-below)

1. From your projects root folder in terminal run:

```
    composer require novay/laravel-uuid:2.0
```

2. Register the package with laravel in `config/app.php` under `aliases` with the following:

```
    'aliases' => [
        'Uuid' => Novay\Uuid\Uuid::class,
    ];
```

### Basic Usage

[](#basic-usage)

To quickly generate a UUID just do

```
    Uuid::generate()
```

- This will generate a version 1 with a random ganerated MAC address.

To echo out the generated Uuid cast it to a string

```
(string) Uuid::generate()
```

or

```
Uuid::generate()->string
```

### Advanced Usage

[](#advanced-usage)

#### UUID creation

[](#uuid-creation)

##### UUID V1

[](#uuid-v1)

Generate a version 1, time-based, UUID. You can set the optional node to the MAC address. If not supplied it will generate a random MAC address.

```
Uuid::generate(1,'00:11:22:33:44:55');
```

##### UUID V3

[](#uuid-v3)

Generate a version 3, name-based using MD5 hashing, UUID

```
Uuid::generate(3,'test', Uuid::NS_DNS);
```

##### UUID V4

[](#uuid-v4)

Generate a version 4, truly random, UUID

```
Uuid::generate(4);
```

##### UUID V5

[](#uuid-v5)

Generate a version 5, name-based using SHA-1 hashing, UUID

```
Uuid::generate(5,'test', Uuid::NS_DNS);
```

### Additional Features

[](#additional-features)

###### Import UUID

[](#import-uuid)

- To import a UUID

```
$uuid = Uuid::import('d3d29d70-1d25-11e3-8591-034165a3a613');
```

###### Extract Time

[](#extract-time)

- Extract the time for a time-based UUID (version 1)

```
$uuid = Uuid::generate(1);
dd($uuid->time);
```

###### Extract Version

[](#extract-version)

- Extract the version of an UUID

```
$uuid = Uuid::generate(4);
dd($uuid->version);
```

###### Eloquent UUID Generation

[](#eloquent-uuid-generation)

If you want an UUID magically be generated in your Laravel models, just add this boot function to your Model.

```
/**
 *  Setup model event hooks
 */
public static function boot()
{
    parent::boot();
    self::creating(function ($model) {
        $model->uuid = (string) Uuid::generate(4);
    });
}
```

This will generate a version 4 UUID when creating a new record.

###### Model Binding to UUID instead of Primary Key

[](#model-binding-to-uuid-instead-of-primary-key)

If you want to use the UUID in URLs instead of the primary key, you can add this to your model (where 'uuid' is the column name to store the UUID)

```
/**
 * Get the route key for the model.
 *
 * @return string
 */
public function getRouteKeyName()
{
    return 'uuid';
}
```

When you inject the model on your resource controller methods you get the correct record

```
public function edit(Model $model)
{
   return view('someview.edit')->with([
        'model' => $model,
    ]);
}
```

###### Validation

[](#validation)

Just use like any other Laravel validator.

`'uuid-field' => 'uuid'`

Or create a validator from scratch. In the example an Uuid object in validated. You can also validate strings `$uuid->string`, the URN `$uuid->urn` or the binary value `$uuid->bytes`

```
$uuid = Uuid::generate();
$validator = Validator::make(['uuid' => $uuid], ['uuid' => 'uuid']);
dd($validator->passes());
```

### Credits

[](#credits)

- Full development credit must go to [webpatser](https://github.com/webpatser). This package was forked and modified to be compliant with [MIT](https://opensource.org/licenses/MIT) licensing standards for production use.

Notes
-----

[](#notes)

Full details on the UUID specification can be found [here](http://tools.ietf.org/html/rfc4122)

License
-------

[](#license)

Laravel UUID is licensed under the MIT license for both personal and commercial products. Enjoy!

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

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

Total

2

Last Release

3026d ago

Major Versions

v2.0 → v3.02018-01-28

PHP version history (2 changes)v2.0PHP &gt;=5.3.0

v3.0PHP &gt;=7.0.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/712577?v=4)[Novianto Rahmadi](/maintainers/novay)[@novay](https://github.com/novay)

---

Tags

UUID RFC4122

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[wujunze/laravel-id-generate

Laravel package to generate and to validate a UUID according to the RFC 4122 standard. Only support for version 1, 3, 4 and 5 UUID are built-in. and generate number id, generate primary key

134.4k](/packages/wujunze-laravel-id-generate)[laravel-ready/license-connector

Connector package for License Server

351.8k](/packages/laravel-ready-license-connector)

PHPackages © 2026

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