tankfairies / laravel-guid
Laravel GUID Generator
Installs: 1 061
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Requires
- php: ^8.2
- tankfairies/guid: 2.*
Requires (Dev)
README
Laravel GUID
This Laravel package is useful for creating globally unique identifiers (GUID).
Installation
Install with Composer:
composer require tankfairies/laravel-guid
Usage
There are four GUID types available. GUID Version: -
GuidInterface::UUID_TIME -> Time based UUID (version 1)
GuidInterface::UUID_NAME_MD5 -> Name based (MD5) UUID (version 3)
GuidInterface::UUID_RANDOM -> Random UUID (version 4)
GuidInterface::UUID_NAME_SHA1 -> Name based (SHA1) UUID (version 5)
All the GUIDs can be generated in one of three formats String, binary and byte. GUID format: -
GuidInterface::FMT_STRING
GuidInterface::FMT_BINARY
GuidInterface::FMT_BYTE
Laravel
Register the package service provider in config/app.php
file.
'providers' => [ Tankfairies\LaravelGuid\GuidServiceProvider::class, ]
Create GUID
This will generate a random GUID
echo "GUID: " . guid(); // example output: 2b23924f-0eaa-4133-848e-7ce1edeca8c9
The guid function has four parameters: -
guid(version, format, salt, namespace)
The salt needs to be at least 6 characters long and is only required for a UUID_TIME
. It can also be optionally used for UUID_NAME_MD5
and UUID_NAME_SHA1
.
UUID_NAME_MD5
and UUID_NAME_SHA1
require the namespace parameter to be filled.
Copyright and license
The tankfairies/laravel-guid library is Copyright (c) 2019 Tankfairies (https://tankfairies.com) and licensed for use under the MIT License (MIT).