Download the PHP package wujunze/laravel-id-generate without Composer
On this page you can find all versions of the php package wujunze/laravel-id-generate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wujunze/laravel-id-generate
More information about wujunze/laravel-id-generate
Files in wujunze/laravel-id-generate
Package laravel-id-generate
Short Description 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
License MIT
Informations about the package laravel-id-generate
Laravel IdGen
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
Thanks to laravel-uuid
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
after installation you should see
and you are ready to go
Basic Usage
To quickly generate a UUID just do
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
or
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.
Generate a version 3, name-based using MD5 hashing, UUID
Generate a version 4, truly random, UUID
Generate a version 5, name-based using SHA-1 hashing, UUID
id generate
Generate sample primary key
Generate id by type and share key
Generate id by type
Generate code
Generate SnowFlake Id
Some magic features
To import a UUID
Extract the time for a time-based UUID (version 1)
Extract the version of an UUID
Eloquent UUID generation
If you want an UUID magically be generated in your Laravel models, just add this boot method to your Model.
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)
When you inject the model on your resource controller methods you get the correct record
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
Notes
Full details on the UUID specification can be found on http://tools.ietf.org/html/rfc4122.
Snowflake is a network service for generating unique ID numbers at high scale with some simple guarantees.