All Projects → webpatser → Laravel Uuid

webpatser / Laravel Uuid

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.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to Laravel Uuid

Ksuid
Java implementation of K-Sortable Globally Unique IDs
Stars: ✭ 35 (-97.96%)
Mutual labels:  uuid
Uuid Random
Fastest UUID with cryptographic PRNG for JS
Stars: ✭ 87 (-94.93%)
Mutual labels:  uuid
User Bundle
A new Symfony user bundle
Stars: ✭ 116 (-93.24%)
Mutual labels:  uuid
Kirby3 Autoid
Automatic unique ID for Pages, Files and Structures including performant helpers to retrieve them. Bonus: Tiny-URL.
Stars: ✭ 58 (-96.62%)
Mutual labels:  uuid
Uuid Shortener
A simple RFC 4122 UUID shortener library. Change your long 36 chars long ID into it's shorter equivalent.
Stars: ✭ 81 (-95.28%)
Mutual labels:  uuid
Laravel Uuid
laravel uuid a simple, automatic UUID generator for any model based on Laravel
Stars: ✭ 103 (-94%)
Mutual labels:  uuid
Node Scalable Blob Store
A file system blob store that is designed to prevent conflicts when used with a distributed file system or storage area network
Stars: ✭ 31 (-98.19%)
Mutual labels:  uuid
Electrode Csrf Jwt
Stateless Cross-Site Request Forgery (CSRF) protection with JWT
Stars: ✭ 127 (-92.6%)
Mutual labels:  uuid
Echo360
Commandline tool for automated downloads of echo360 videos hosted by university
Stars: ✭ 81 (-95.28%)
Mutual labels:  uuid
Snowflake
java edition of [Twitter Snowflake](https://github.com/twitter/snowflake), a network service for generating unique ID numbers at high scale with some simple guarantees.
Stars: ✭ 114 (-93.36%)
Mutual labels:  uuid
Ble
✨Android BLE基础操作框架,基于回调,操作简单。包含扫描、多连接、广播包解析、服务读写及通知等功能。
Stars: ✭ 1,183 (-31.1%)
Mutual labels:  uuid
Uuid Creator
A Java library for generating and handling RFC-4122 UUIDs.
Stars: ✭ 78 (-95.46%)
Mutual labels:  uuid
Ardent
Self-validating, secure and smart models for Laravel's Eloquent ORM
Stars: ✭ 1,412 (-17.76%)
Mutual labels:  laravel-validation
Ar Uuid
Override migration methods to support UUID columns without having to be explicit about it.
Stars: ✭ 41 (-97.61%)
Mutual labels:  uuid
Symfony Demo App
A Symfony demo application with basic user management
Stars: ✭ 122 (-92.89%)
Mutual labels:  uuid
Instauuid
Instagram-Style Compact UUID generator library for Node.js
Stars: ✭ 31 (-98.19%)
Mutual labels:  uuid
Fcuuid
iOS UUID / Universally Unique Identifiers library as alternative to UDID and identifierForVendor. 📱
Stars: ✭ 1,387 (-19.22%)
Mutual labels:  uuid
Flake
Decentralized, k-ordered unique IDs in Clojure
Stars: ✭ 132 (-92.31%)
Mutual labels:  uuid
Javascript
Universally Unique Lexicographically Sortable Identifier
Stars: ✭ 1,781 (+3.73%)
Mutual labels:  uuid
Fast Uuid
A Java library for quickly and efficiently parsing and writing UUIDs
Stars: ✭ 114 (-93.36%)
Mutual labels:  uuid

Laravel Uuid

Total Downloads Build Status codecov.io Latest Stable Version Licence

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.*

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.*

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

Laravel 4.*? use version 1

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

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

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

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

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

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

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

Full details on the UUID specification can be found on http://tools.ietf.org/html/rfc4122.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].