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

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

jasurbek97/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.

4.0(5y ago)123MITPHPPHP ^7.0|^8.0

Since Sep 14Pushed 5y agoCompare

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

READMEChangelogDependencies (2)Versions (22)Used By (0)

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

[](#laravel-uuid)

[![Total Downloads](https://camo.githubusercontent.com/9828aa6f340c3f25318bbea0a65d1a7009593966483f6c4735af8c88e1640eec/68747470733a2f2f706f7365722e707567782e6f72672f6a6173757262656b39372f6c61726176656c2d757569642f646f776e6c6f6164732e737667)](https://packagist.org/packages/jasurbek97/laravel-uuid)[![Build Status](https://camo.githubusercontent.com/d107512e928c08f25859328a5404200d16ba5d8ee462d878a319acd0a1070b5a/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6a6173757262656b39372f6c61726176656c2d757569642e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/jasurbek97/laravel-uuid)[![codecov.io](https://camo.githubusercontent.com/c48c121e5de1759ba58ee1f0796ba397f618e0e6818c8dd2ba91f18d68da8050/687474703a2f2f636f6465636f762e696f2f6769746875622f6a6173757262656b39372f6c61726176656c2d757569642f636f7665726167652e7376673f6272616e63683d6d6173746572)](http://codecov.io/github/jasurbek97/laravel-uuid?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/9fb6b4f6ea1d1c8381050d15b4dc9abd686f156e0dc5cc7eaf4b51fd2b641b27/68747470733a2f2f706f7365722e707567782e6f72672f6a6173757262656b39372f6c61726176656c2d757569642f762f737461626c652e737667)](https://packagist.org/packages/jasurbek97/laravel-uuid)[![Licence](https://camo.githubusercontent.com/2a1afbecb828064ea3a46880317d848c4128fa0c572f7ccb15212d79655379ba/68747470733a2f2f706f7365722e707567782e6f72672f6a6173757262656b39372f6c61726176656c2d757569642f6c6963656e73652e737667)](https://packagist.org/packages/jasurbek97/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/jasurbek97/laravel-uuid/tree/2.1.1)

Laravel 4.\*? use [version 1](https://github.com/jasurbek97/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 "jasurbek97/laravel-uuid:^4.0"
```

after installation you should see

```
Discovered Package: jasurbek97/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

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 83.9% 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 ~139 days

Recently: every ~298 days

Total

20

Last Release

1976d ago

Major Versions

1.5 → 2.02015-06-15

2.1.1 → 3.02017-09-03

1.0.x-dev → 3.0.22017-10-04

2.0.x-dev → 4.02020-12-14

PHP version history (3 changes)1.0PHP &gt;=5.3.0

3.0PHP ^7.0

4.0PHP ^7.0|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ad00a27e6b49764307949257adcba9a720fbef6c7aa9de879039a64e78d364b?d=identicon)[jasurbek97](/maintainers/jasurbek97)

---

Top Contributors

[![webpatser](https://avatars.githubusercontent.com/u/25720?v=4)](https://github.com/webpatser "webpatser (78 commits)")[![KuroThing](https://avatars.githubusercontent.com/u/18753877?v=4)](https://github.com/KuroThing "KuroThing (4 commits)")[![freezy-sk](https://avatars.githubusercontent.com/u/661637?v=4)](https://github.com/freezy-sk "freezy-sk (2 commits)")[![milanowicz](https://avatars.githubusercontent.com/u/1786103?v=4)](https://github.com/milanowicz "milanowicz (2 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)")[![rankarpan](https://avatars.githubusercontent.com/u/9264092?v=4)](https://github.com/rankarpan "rankarpan (1 commits)")[![Omranic](https://avatars.githubusercontent.com/u/406705?v=4)](https://github.com/Omranic "Omranic (1 commits)")[![a3020](https://avatars.githubusercontent.com/u/1431100?v=4)](https://github.com/a3020 "a3020 (1 commits)")[![russianryebread](https://avatars.githubusercontent.com/u/747085?v=4)](https://github.com/russianryebread "russianryebread (1 commits)")

---

Tags

UUID RFC4122

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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