Laravel package to generate a UUID according to the RFC 4122 standard. UUID Versions 1, 3, 4 and 5 are supported. With MIT license.
Requires
- php: >=5.3.0
Requires (Dev)
- fzaninotto/faker: 1.5.*
- phpunit/phpunit: 4.7.*
Suggests
- paragonie/random_compat: A random_bytes Php 5.x polyfill.
This package is auto-updated.
Last update: 2024-10-29 05:28:29 UTC
README
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
- Requirements
- Installation
- Basic Usage
- Advanced Usage
- Additional Features
- Changelog
- License
- Credits
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
Installation
- From your projects root folder in terminal run:
composer require rubiconinternational/uuid
- Register the package with laravel in
config/app.php
underaliases
with the following:
'aliases' => [ 'Uuid' => rubiconinternational\Uuid\Uuid::class, ];
Basic Usage
To quickly generate a UUID just do
Uuid::generate()
- This will generate a version 1 with a random ganerated MAC address.
Advanced Usage
UUID creation
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
Generate a version 3, name-based using MD5 hashing, UUID
Uuid::generate(3,'test', Uuid::NS_DNS);
UUID V4
Generate a version 4, truly random, UUID
Uuid::generate(4);
UUID V5
Generate a version 5, name-based using SHA-1 hashing, UUID
Uuid::generate(5,'test', Uuid::NS_DNS);
Additional Features
Import UUID
- To import a UUID
$uuid = Uuid::import('d3d29d70-1d25-11e3-8591-034165a3a613');
Extract Time
- Extract the time for a time-based UUID (version 1)
$uuid = Uuid::generate(1); dd($uuid->time);
Extract Version
- Extract the version of an UUID
$uuid = Uuid::generate(4); dd($uuid->version);
Changelog
2.*
- Laravel Uuid is now fully PSR-2, just like Laravel 5.1.
- Not that much has changed except for UPPERCASING the constants used in Laravel Uuid.
- Meaning
Uuid::nsDNS
is nowUuid::NS_DNS
etc. Should be an easy fix.
Credits
- Full development credit must go to webpatser. This package was forked and modified to be compliant with MIT licencing standards for production use.
License
Laravel UUID is licensed under the MIT license for both personal and commercial products. Enjoy!