ramsey/uuid
ramsey/uuid is a PHP library for generating and working with universally unique identifiers (UUIDs). Install it via Composer, then generate, parse, and validate UUIDs across versions, with support for version 3, 4, 5, 6, 7, and 8.
Primary key and identifier strategy (the decision this package actually serves). ramsey/uuid lets a PM choose an ID scheme as a product decision rather than a database default. The library covers RFC 9562 versions 1–8, nil and max UUIDs, plus parsing, validation, and conversion — so the choice between opaque, time-ordered, or deterministic IDs is a configuration and roadmap conversation, not a rewrite.
Uuid::isValid(), fromString(), and typed version objects let the team reject malformed IDs from partners, webhooks, and imports with a single, RFC-correct check — replacing a graveyard of regexes.OrderedTimeCodec, TimestampFirstCombCodec, TimestampLastCombCodec, and CombGenerator are deprecated in favor of UUIDv6/v7. Any Laravel app relying on legacy Str::orderedUuid()-style COMB behavior has scheduled tech debt; the PM decision is "migrate to v7 before 5.0 lands," not "wait for breakage."uuid). The library can emit and consume both string and byte forms (getBytes(), fromBytes()), so this becomes a measurable trade-off — index size and join performance vs debuggability — rather than a library constraint.random_bytes + sprintf). Everything past that — version/variant decoding, RFC 9562 edge cases (nil/max variants, uppercase, lazy parsing, v7 monotonicity within a millisecond), and staying current with a moving RFC — is where the package earns its keep at zero license cost.Adopt when:
Look elsewhere (or decide deliberately against UUIDs) when:
random_bytes()-based opaque tokens internally, with no parsing, no external IDs, and no version semantics — the dependency is then ceremony.Adoption criteria checklist: confirm runtime is PHP 8.x; confirm Laravel/Symfony version and whether the package is already resolved in composer.lock; pick the UUID version per table before the first migration; decide column type (native uuid, binary(16), or char(36)) with a measured index-size comparison; verify ext-ctype is present or add a polyfill.
To executives (2 minutes): "This is a free, MIT-licensed, widely trusted PHP library for generating and parsing unique identifiers — the IDs that appear in our URLs, APIs, and database keys. It's almost certainly already installed as a transitive dependency, so this is a standardization decision, not a new vendor. The business value is threefold: (1) we stop writing and maintaining bespoke ID code, which is a recurring source of duplicate-record and data-merge bugs; (2) moving new tables to time-ordered UUIDs lets us generate IDs in the app — enabling offline capture and faster feature delivery — while keeping database insert performance healthy; (3) non-guessable public IDs reduce enumeration and scraping risk. Cost is zero; optional commercial support is available via Tidelift if procurement wants a support contract for audit purposes. The one commitment I'm asking for is a small, scoped migration of our legacy ordered-ID code ahead of the library's next major version."
To engineering (the ask): "Adopt ramsey/uuid as the single source of truth for identifier generation and validation. New tables default to UUIDv7 with a documented column type; public APIs validate inbound IDs with Uuid::isValid() instead of regex; deterministic IDs use v5 against an agreed namespace registry. Retire homegrown helpers and any COMB/orderedUuid-style code paths — those codecs are deprecated in 4.8 and removed in 5.0. Two deliverables before we commit: a benchmark of the chosen column type (native uuid vs binary(16) vs char(36)) on our actual write volume, and a short ADR recording why we chose v7 over v4 or Snowflake. Effort is small; the payoff is one fewer class of identity bugs and a clean upgrade path."
How can I help you explore Laravel packages today?