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
🔍 UUID Validator & Inspector
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 output
The block below generates one UUID per version on this server, each next to the call that produced it. Press Generate again for new values. The name-based rows are always the same for the same name and namespace.
-
Uuid::v4()v4, random864e5ef5-00a5-4c73-926e-8cb4e03b259e -
Uuid::v7()v7, time-ordered01a23843-382e-7005-9f66-169545d1bb52 -
Uuid::generate(1)v1, time and noded543e8c0-ee87-11f1-8401-2bfc58ddbfc4 -
Uuid::generate(3, 'example.com', Uuid::NS_DNS)v3, MD5 name-based9073926b-929f-31c2-abc9-fad77ae3e8eb -
Uuid::generate(5, 'example.com', Uuid::NS_DNS)v5, SHA-1 name-basedcfbff0d1-9375-5685-968c-48ce8b15ae17 -
Uuid::generate(6)v6, time-ordered (RFC 9562)1f1ee87d-543e-6930-8305-97c76c678ef5 -
Uuid::generate(8)v8, custom95e319b9-d204-8c6d-bbdf-4f4ac4ae848b -
Uuid::nil()Nil00000000-0000-0000-0000-000000000000
The v3 and v5 values stay the same on every view; the others change each time.
This demo runs webpatser/uuid 3.0.0, the version installed on this site.
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);
Note: v3 and v5 with the 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 }); }}