Laravel UUID
Laravel package to generate and validate (UUID)s according to RFC 4122 standard., (*1)
Support for version 4 currently only.., (*2)
Laravel 5.5 package auto discovery support., (*3)
Installation
Install to your project using composer by running the following command:, (*4)
composer require "alexchadwick/laravel-uuid
For Laravel 5.5, after installation you should see:, (*5)
Discovered Package: alexchadwick/laravel-uuid
Usage
To generate UUID
$uuid = (string) Uuid::generate()
OR, (*6)
$uuid = Uuid::generate()->string
To generate specific version of UUID
//generate UUIDv4
$uuid = (string) Uuid::generate(4)
OR, (*7)
//generate UUIDv4
$uuid = Uuid::uuid4(4)
Eloquent model UUID
The built in Trait "HasUuidPrimaryKey", will automatically generate a UUIDv4 and set it on the model's primary key field when creating model., (*8)
This will not affect model events since the Trait makes uses Laravel Model's bootTraits() function., (*9)
Validation
Using the Laravel validator, you can now pass the rule name "uuid" to validate UUIDs., (*10)
Laravel validator rule example, (*11)
'YOUR-UUID-FIELD' => 'uuid'
Running tests
Tests are location in ./test, run phpunit to run built test., (*12)