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

ActiveLibrary

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

018.0k↓50%11PHP

Since Apr 13Pushed 3y agoCompare

[ Source](https://github.com/Fly-Now-Pay-Later/laravel-uuid)[ Packagist](https://packagist.org/packages/flynowpaylater/laravel-uuid)[ RSS](/packages/flynowpaylater-laravel-uuid/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (1)

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

[](#laravel-uuid)

[![Total Downloads](https://camo.githubusercontent.com/2286476a1bfbab7d5c26214a30a0b95c5237b6c333f3a84a5bab62c3ed2b90a5/68747470733a2f2f706f7365722e707567782e6f72672f7765627061747365722f6c61726176656c2d757569642f646f776e6c6f6164732e737667)](https://packagist.org/packages/webpatser/laravel-uuid)[![Build Status](https://camo.githubusercontent.com/1c476fe37642aa9faa2672346bb1ea0848322c47c6bcff203c77b8ac01d92375/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f7765627061747365722f6c61726176656c2d757569642e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/webpatser/laravel-uuid)[![codecov.io](https://camo.githubusercontent.com/7ccd1a6219e85b9bac0af3d77d9fa506d22ade6fd7716a62825da5461ffd204b/687474703a2f2f636f6465636f762e696f2f6769746875622f7765627061747365722f6c61726176656c2d757569642f636f7665726167652e7376673f6272616e63683d6d6173746572)](http://codecov.io/github/webpatser/laravel-uuid?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/d213868259ce504fe65ad5ce4c03ff48f8f790fa4c1b9aff161414b13938c595/68747470733a2f2f706f7365722e707567782e6f72672f7765627061747365722f6c61726176656c2d757569642f762f737461626c652e737667)](https://packagist.org/packages/webpatser/laravel-uuid)[![Licence](https://camo.githubusercontent.com/45c73d4fb42cc6913b44912beb2ecbc2697e270c13be4af03f199cfc162af380/68747470733a2f2f706f7365722e707567782e6f72672f7765627061747365722f6c61726176656c2d757569642f6c6963656e73652e737667)](https://packagist.org/packages/webpatser/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/webpatser/laravel-uuid/tree/2.1.1)

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

after installation you should see

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

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity22

Early-stage or recently created project

 Bus Factor1

Top contributor holds 81.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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/19610073?v=4)[Edgars Kohs](/maintainers/ed9)[@ed9](https://github.com/ed9)

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

---

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)")[![ezitisitis](https://avatars.githubusercontent.com/u/6075434?v=4)](https://github.com/ezitisitis "ezitisitis (2 commits)")[![freezy-sk](https://avatars.githubusercontent.com/u/661637?v=4)](https://github.com/freezy-sk "freezy-sk (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)")[![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)")[![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)")[![russianryebread](https://avatars.githubusercontent.com/u/747085?v=4)](https://github.com/russianryebread "russianryebread (1 commits)")

### Embed Badge

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

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

PHPackages © 2026

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