Download the PHP package novay/laravel-uuid without Composer
On this page you can find all versions of the php package novay/laravel-uuid. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download novay/laravel-uuid
More information about novay/laravel-uuid
Files in novay/laravel-uuid
Package laravel-uuid
Short Description Laravel package to generate and to validate a UUID according to the RFC 4122 standard. UUID Versions 1, 3, 4 and 5 are supported.
License MIT
Homepage https://github.com/novay/laravel-uuid
Informations about the package laravel-uuid
Laravel UUID (Universally Unique Identifier)
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
- Laravel 5.5 and above
- Laravel 5.4 and below
- Basic Usage
- Advanced Usage
- UUID creation
- UUID V1
- UUID V3
- UUID V4
- UUID V5
- UUID creation
- Additional Features
- Import UUID
- Extract time
- Extract Version
- Eloquent UUID Generation
- Model Binding to UUID instead of Primary Key
- Validation
- License
- Notes
- 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
Laravel 5.5 and above
- From your projects root folder in terminal run:
- Uses package auto discovery feature, no need to edit the
config/app.php
file.
Laravel 5.4 and below
-
From your projects root folder in terminal run:
- Register the package with laravel in
config/app.php
underaliases
with the following:
Basic Usage
To quickly generate a UUID just do
- This will generate a version 1 with a random ganerated MAC address.
To echo out the generated Uuid cast it to a string
or
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 V3
Generate a version 3, name-based using MD5 hashing, UUID
UUID V4
Generate a version 4, truly random, UUID
UUID V5
Generate a version 5, name-based using SHA-1 hashing, UUID
Additional Features
Import UUID
- To import a UUID
Extract Time
- Extract the time for a time-based UUID (version 1)
Extract Version
- 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 function 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'
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
Credits
- Full development credit must go to webpatser. This package was forked and modified to be compliant with MIT licensing standards for production use.
Notes
Full details on the UUID specification can be found here
License
Laravel UUID is licensed under the MIT license for both personal and commercial products. Enjoy!