PHPackages                             klongchu/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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. klongchu/laravel-uuid

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

klongchu/laravel-uuid
=====================

Laravel package to generate and to validate a universally unique identifier (UUID) according to the RFC 4122 standard. Support for version 1, 3, 4 and 5 UUIDs are built-in.

1.0.0(1y ago)07MITPHPPHP ^7.0|^8.0|^8.1|^8.2

Since Jun 20Pushed 1y agoCompare

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

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

Laravel Uuid
============

[](#laravel-uuid)

[![Total Downloads](https://camo.githubusercontent.com/63540ab15bd85b046ce88ccf2da0bb3464c97dda01c4541bb000fd171a215f5b/68747470733a2f2f706f7365722e707567782e6f72672f6b6c6f6e676368752f6c61726176656c2d757569642f646f776e6c6f6164732e737667)](https://packagist.org/packages/klongchu/laravel-uuid)[![Build Status](https://camo.githubusercontent.com/e382d6c5c38767e5a676b225ddee088de68cb9ec411c730ba93c6f5756b3a732/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6b6c6f6e676368752f6c61726176656c2d757569642e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/klongchu/laravel-uuid)[![codecov.io](https://camo.githubusercontent.com/1faefe423ebf53b5033ce894b8720e839d2b9b96650eddc4a912a949946c9790/687474703a2f2f636f6465636f762e696f2f6769746875622f6b6c6f6e676368752f6c61726176656c2d757569642f636f7665726167652e7376673f6272616e63683d6d6173746572)](http://codecov.io/github/klongchu/laravel-uuid?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/63e3369c63b0a5687ff6277d8a34f29aa7f3c7fba3e4091b51ee3d885c7cfcf9/68747470733a2f2f706f7365722e707567782e6f72672f6b6c6f6e676368752f6c61726176656c2d757569642f762f737461626c652e737667)](https://packagist.org/packages/klongchu/laravel-uuid)[![Licence](https://camo.githubusercontent.com/34e1accd0eec80416580ca357dad0e7c891dc08752ca704366ee8c7430894e90/68747470733a2f2f706f7365722e707567782e6f72672f6b6c6f6e676368752f6c61726176656c2d757569642f6c6963656e73652e737667)](https://packagist.org/packages/klongchu/laravel-uuid)

Laravel package to generate and to validate a universally unique identifier (UUID) according to the RFC 4122 standard. Support for version 1, 3, 4 and 5 UUIDs are built-in.

What's new in 4.\*
------------------

[](#whats-new-in-4)

Laravel-uuid is now ready for Laravel 8. It has the same requirements so that means PHP 7.3 or PHP 8. Laravel package auto-discovery is enabled, and you can now use the UUID validation. Validation examples are below and in the tests.

For older Laravel or PHP versions use older versions; see below...

What's new in 3.\*
------------------

[](#whats-new-in-3)

Laravel-uuid is now refactored for Laravel 5.5. It has the same requirements so that means PHP 7. Laravel package auto-discovery is enabled, and you can now use the UUID validation. Validation examples are below and in the tests.

Laravel 5.0, 5.1, 5.2, 5.3 and 5.4? use [version 2](https://github.com/klongchu/laravel-uuid/tree/2.1.1)

Laravel 4.\*? use [version 1](https://github.com/klongchu/laravel-uuid/tree/1.5)

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

[](#installation)

In Laravel 5.5 laravel-uuid will install via the new package discovery feature so you only need to add the package to your composer.json file

```
composer require "klongchu/laravel-uuid:^3.0"
```

after installation you should see

```
Discovered Package: klongchu/laravel-uuid
```

and you are ready to go

Basic Usage
-----------

[](#basic-usage)

To quickly generate a UUID just do

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

This will generate a version 1 Uuid `object` with a random generated 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)

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');
```

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

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

Generate a version 4, truly random, UUID

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

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

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

### Some magic features

[](#some-magic-features)

To import a UUID

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

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

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

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 method 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());
```

Notes
-----

[](#notes)

Full details on the UUID specification can be found on .

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80.8% 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

Unknown

Total

1

Last Release

691d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6489801?v=4)[Klongchu Dev BUDHOSP](/maintainers/klongchu)[@klongchu](https://github.com/klongchu)

---

Top Contributors

[![webpatser](https://avatars.githubusercontent.com/u/25720?v=4)](https://github.com/webpatser "webpatser (80 commits)")[![KuroThing](https://avatars.githubusercontent.com/u/18753877?v=4)](https://github.com/KuroThing "KuroThing (4 commits)")[![milanowicz](https://avatars.githubusercontent.com/u/1786103?v=4)](https://github.com/milanowicz "milanowicz (2 commits)")[![freezy-sk](https://avatars.githubusercontent.com/u/661637?v=4)](https://github.com/freezy-sk "freezy-sk (2 commits)")[![ezitisitis](https://avatars.githubusercontent.com/u/6075434?v=4)](https://github.com/ezitisitis "ezitisitis (2 commits)")[![russianryebread](https://avatars.githubusercontent.com/u/747085?v=4)](https://github.com/russianryebread "russianryebread (1 commits)")[![samnela](https://avatars.githubusercontent.com/u/1852108?v=4)](https://github.com/samnela "samnela (1 commits)")[![vinicius73](https://avatars.githubusercontent.com/u/1561347?v=4)](https://github.com/vinicius73 "vinicius73 (1 commits)")[![vtek21](https://avatars.githubusercontent.com/u/36813?v=4)](https://github.com/vtek21 "vtek21 (1 commits)")[![Omranic](https://avatars.githubusercontent.com/u/406705?v=4)](https://github.com/Omranic "Omranic (1 commits)")[![apiruknetway](https://avatars.githubusercontent.com/u/49223076?v=4)](https://github.com/apiruknetway "apiruknetway (1 commits)")[![klongchu](https://avatars.githubusercontent.com/u/6489801?v=4)](https://github.com/klongchu "klongchu (1 commits)")[![a3020](https://avatars.githubusercontent.com/u/1431100?v=4)](https://github.com/a3020 "a3020 (1 commits)")[![rankarpan](https://avatars.githubusercontent.com/u/9264092?v=4)](https://github.com/rankarpan "rankarpan (1 commits)")

---

Tags

UUID RFC4122

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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