UUID Library v1.3.0
Interactive UUID Examples
webpatser@dev:
~/uuid/1.3.0
$ cat examples.md
Live Examples - UUID Library v1.3.0
Interactive examples showing all UUID versions with real-time generation. Click the buttons to generate new UUIDs!
Interactive UUID Generation & Validation
Each UUID version serves different purposes. Use the interactive tools below to generate new UUIDs and validate existing ones:
⚡ Quick Actions
This interactive experience is powered by Laravel, Livewire & PHP — using the actual UUID library for real-time generation and validation
🎲 Interactive UUID Generator
b51e4c0d-3d40-4cbb-98de-770f87931100
b51e4c0d3d404cbb98de770f87931100
b51e4c0d3d404cbb98de770f87931100
🔍 UUID Validator & Inspector
Enter a UUID above to validate
Usage Examples
Basic Generation
use Webpatser\Uuid\Uuid; // Random UUID (most common)$uuid = Uuid::v4();echo $uuid; // e.g., "f47ac10b-58cc-4372-a567-0e02b2c3d479" // Time-based UUID$timeUuid = Uuid::v1();echo $timeUuid; // e.g., "6ba7b810-9dad-11d1-80b4-00c04fd430c8" // Modern timestamp UUID (recommended for databases)$modernUuid = Uuid::v7();echo $modernUuid; // e.g., "018f4e7c-8b3a-7000-8000-123456789abc"
Live Generation Results
v4 (Random)
0ae57685-6450-4e34-8087-46276db1df54
v1 (Time)
ce6389e0-9083-11f0-b2a0-6549c7c03ec5
v7 (Modern)
01994266-44df-7007-8fc9-8fee1f981132
Name-based UUIDs
use Webpatser\Uuid\Uuid; // Deterministic UUIDs from names$uuid3 = Uuid::generate(3, 'example.com', Uuid::NS_DNS);echo $uuid3; // Always: 9073926b-929f-31c2-abc9-fad77ae3e8eb $uuid5 = Uuid::generate(5, 'example.com', Uuid::NS_DNS);echo $uuid5; // Always: cfbff0d1-9375-5685-968c-48ce8b15ae17 // Custom namespace$customNamespace = Uuid::v4();$customUuid = Uuid::generate(5, 'my-data', $customNamespace);
Deterministic Examples
v3('example.com', NS_DNS):
9073926b-929f-31c2-abc9-fad77ae3e8eb
v5('example.com', NS_DNS):
cfbff0d1-9375-5685-968c-48ce8b15ae17
Custom namespace:
21f19376-8752-5658-b6aa-cbfa5fb79970
Note: v3 and v5 with same input always generate the same UUID
Code Examples
Copy these examples to get started:
use Webpatser\Uuid\Uuid; // Most common patterns$randomUuid = Uuid::v4(); // General purpose$timestampUuid = Uuid::v7(); // Database records$deterministicUuid = Uuid::generate(5, $name, Uuid::NS_DNS); // From name // Different formatsecho $randomUuid->string; // "123e4567-e89b-12d3-a456-426614174000"echo $randomUuid->hex; // "123e4567e89b12d3a456426614174000"echo bin2hex($randomUuid->bytes); // Same as hex // Validation and comparisonif (Uuid::validate($input)) { $uuid = Uuid::import($input); if (Uuid::compare($uuid, $otherUuid)) { echo "UUIDs match!"; }}
Advanced Examples
Batch Generation
use Webpatser\Uuid\Uuid; // Generate multiple UUIDs efficiently$uuids = [];for ($i = 0; $i < 1000; $i++) { $uuids[] = Uuid::v7(); // Time-ordered for better database performance} // Custom namespace for your application$appNamespace = Uuid::generate(5, 'myapp.com', Uuid::NS_DNS); // Generate deterministic UUIDs for users$userIds = [];foreach (['alice', 'bob', 'charlie'] as $username) { $userIds[$username] = Uuid::generate(5, $username, $appNamespace);}
Database Usage
use Webpatser\Uuid\Uuid; // Laravel migration exampleSchema::create('users', function (Blueprint $table) { $table->uuid('id')->primary(); $table->string('email')->unique(); $table->timestamps();}); // Model with UUID primary keyclass User extends Model{ protected $keyType = 'string'; public $incrementing = false; protected static function boot() { parent::boot(); static::creating(function ($model) { $model->id = Uuid::v7(); // Time-ordered for better DB performance }); }}