PHPackages                             wujunze/laravel-id-generate - 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. wujunze/laravel-id-generate

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

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

1.0.6(7y ago)134.4k↓100%2MITPHPPHP ^7.1

Since Sep 14Pushed 7y ago2 watchersCompare

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

READMEChangelogDependencies (6)Versions (8)Used By (0)

Laravel IdGen
=============

[](#laravel-idgen)

[![Build Status](https://camo.githubusercontent.com/6dddbfed44c8fb3831361f088b151e842bcc780450e34872c06289055dacd59d/68747470733a2f2f7472617669732d63692e6f72672f77756a756e7a652f6c61726176656c2d69642d67656e65726174652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/wujunze/laravel-id-generate)[![codecov.io](https://camo.githubusercontent.com/e1b19a6e0b1fdd433d73ec167fc859f64bb3e62ae35e1c0edf396ae43ea03e5a/687474703a2f2f636f6465636f762e696f2f6769746875622f77756a756e7a652f6c61726176656c2d69642d67656e65726174652f636f7665726167652e7376673f6272616e63683d6d6173746572)](http://codecov.io/github/wujunze/laravel-id-generate?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/65189277a53a3e9d19f855a5211523f319bdefbf4061afd6c45e6a59d2688229/68747470733a2f2f706f7365722e707567782e6f72672f77756a756e7a652f6c61726176656c2d69642d67656e65726174652f762f737461626c652e737667)](https://packagist.org/packages/wujunze/laravel-id-generate)[![Licence](https://camo.githubusercontent.com/fffb696e30cac4eec1ebfa19e185d56eb54a9eeb9de1e0d08dce00834bf57383/68747470733a2f2f706f7365722e707567782e6f72672f77756a756e7a652f6c61726176656c2d69642d67656e65726174652f6c6963656e73652e737667)](https://packagist.org/packages/wujunze/laravel-id-generate)[![Total Downloads](https://camo.githubusercontent.com/c156fcc423dcc65147f30f02f6d8f4800c0f098c8af77e9796320be12ea0c338/68747470733a2f2f706f7365722e707567782e6f72672f77756a756e7a652f6c61726176656c2d69642d67656e65726174652f646f776e6c6f6164732e737667)](https://packagist.org/packages/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

Base on [laravel-uuid](https://github.com/webpatser/laravel-uuid)
-----------------------------------------------------------------

[](#base-on-laravel-uuid)

Thanks to [laravel-uuid](https://github.com/webpatser/laravel-uuid)
-------------------------------------------------------------------

[](#thanks-to--laravel-uuid)

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 "wujunze/laravel-id-generate"
```

after installation you should see

```
Discovered Package: wujunze/laravel-id-generate
```

and you are ready to go

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

[](#basic-usage)

To quickly generate a UUID just do

```
IdGen::generate()
```

This will generate a version 1 IdGen `object` with a random generated MAC address.

To echo out the generated UUID, cast it to a string

```
(string) IdGen::generate()
```

or

```
IdGen::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.

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

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

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

Generate a version 4, truly random, UUID

```
IdGen::generate(4);
```

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

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

### id generate

[](#id-generate)

Generate sample primary key

```
 IdGen::getSamplePk();
```

Generate id by type and share key

```
 IdGen::genIdByTypeShareKey(6,89);
```

Generate id by type

```
 IdGen::genIdByType(8);
```

Generate code

```
 IdGen::genCode(9, 9, 888);
```

Generate SnowFlake Id

```
 IdGen::snowFlakeId();
```

### Some magic features

[](#some-magic-features)

To import a UUID

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

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

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

Extract the version of an UUID

```
$uuid = IdGen::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) IdGen::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'``'uuid-field' => 'gen_id'`

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

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

Notes
-----

[](#notes)

Full details on the UUID specification can be found on .

[Snowflake](https://github.com/twitter-archive/snowflake) is a network service for generating unique ID numbers at high scale with some simple guarantees.

Inspire And Thanks
------------------

[](#inspire-and-thanks)

[Snowflake php implement](https://blog.csdn.net/envon123/article/details/52953872)

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

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

Total

6

Last Release

2724d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0bf502ba4ce9952fcb8a819f9aca3fa616e237ad8d59a47b9071710e95422c1d?d=identicon)[wujunze](/maintainers/wujunze)

---

Top Contributors

[![wujunze](https://avatars.githubusercontent.com/u/12997869?v=4)](https://github.com/wujunze "wujunze (21 commits)")

---

Tags

laravelphprfc-4122snowflakesnowflake-twitteruuid-generatorphpuuidprimary keyUUID RFC4122

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wujunze-laravel-id-generate/health.svg)

```
[![Health](https://phpackages.com/badges/wujunze-laravel-id-generate/health.svg)](https://phpackages.com/packages/wujunze-laravel-id-generate)
```

###  Alternatives

[monicahq/laravel-cloudflare

Add Cloudflare ip addresses to trusted proxies for Laravel.

3372.7M4](/packages/monicahq-laravel-cloudflare)[bezhansalleh/filament-google-analytics

Google Analytics integration for FilamentPHP

205144.8k5](/packages/bezhansalleh-filament-google-analytics)[fab2s/souuid

Simple Ordered Uuid Generator in PHP

13573.2k1](/packages/fab2s-souuid)[iteks/laravel-enum

A comprehensive Laravel package providing enhanced enum functionalities, including attribute handling, select array conversions, and fluent facade interactions for robust enum management in Laravel applications.

2516.7k](/packages/iteks-laravel-enum)[waad/laravel-profanity-filter

Laravel Profanity Filter - Powerful PHP package for detecting, filtering, and masking profanity in multiple languages. Supports leet speak, custom word lists, case sensitivity, and seamless Laravel integration.

202.9k](/packages/waad-laravel-profanity-filter)

PHPackages © 2026

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