- How do I install symfony/uid in Laravel?
- Run composer require symfony/uid and pin to ^8.1.8 for the latest correctness fixes. Laravel needs no package-specific service provider, but you can bind UidFactoryInterface to UuidV7Factory or UlidFactory in AppServiceProvider. The component requires PHP 8.1+ on 7.4+ or PHP 8.4+ on 8.0+, so confirm your Laravel version supports that PHP version.
- Does symfony/uid work with Laravel 10 and Laravel 11?
- symfony/uid is framework-agnostic and does not publish Laravel-specific version constraints; it works wherever your Laravel release runs a supported PHP version. For v8.x that means PHP 8.4+, while v7.4+ supports PHP 8.1+. Check your Laravel branch's PHP requirement before choosing a major version.
- How do I use a UUID or ULID as an Eloquent primary key?
- Set protected $keyType = 'string' and public $incrementing = false on the model. Assign a UuidInterface or UlidInterface value when creating the record, and add a cast or accessor so Eloquent hydrates the column back into the value object. Keep the database column type aligned with your storage choice, such as UUID or BINARY(16).
- Should I use UUIDv7 or ULID for Laravel applications?
- Both are time-ordered and suitable for distributed ID generation. UUIDv7 follows RFC 9562 and maps cleanly to PostgreSQL UUID columns, while ULID is monotonic and useful when strict lexicographic ordering matters. In multi-region setups, keep clocks NTP-synchronized for UUIDv7 or prefer ULIDs where global ordering is critical.
- How do I validate UUIDs and ULIDs in Laravel with symfony/uid?
- Use Uuid::isValid() and Ulid::isValid() for direct checks, or Laravel's UUID validation rule backed by symfony/validator. Version 8.1.8 tightened Ulid::isValid() so base-58 strings above 2^128 are rejected; audit inbound payloads and stored IDs after upgrading. Add regression tests around any lax validation gates.
- How should I store UUIDs and ULIDs in MySQL or PostgreSQL?
- The component supports string storage in RFC 4122/9562 form, binary storage such as PostgreSQL UUID or MySQL BINARY(16), and Base58 for compact strings. Binary storage typically reduces index and I/O overhead by 20–30% compared with text. Choose one representation per column and convert explicitly at the application boundary.
- How do I test UUID and ULID generation in Laravel?
- Use MockUuidFactory for deterministic fixtures in unit tests and assert against interfaces rather than hardcoded generated strings. Version 8.1.8 fixed clock-regression ordering, so review any assertions that assumed a specific generated value. Also add regression tests for validation and sort order when mixing UUIDs and ULIDs during migration.
- What changed in symfony/uid 8.1.8 and is it safe to upgrade?
- 8.1.8 contains three correctness fixes with no API changes or deprecations: UUIDv7 ordering when the clock moves backwards, stricter Ulid::isValid(), and correct mixed Uuid/Ulid comparison. Treat it as a low-risk patch-level adoption, but audit inbound ULIDs and dedupe, merge, or sort logic where both ID types coexist. Pin to ^8.1.8 rather than ^8.0.9.
- Is symfony/uid production-ready and performant for Laravel APIs?
- Yes; it is a pure PHP component with no framework assumptions and generation is sub-100ns on x64 in the project assessment. Binary database storage further reduces I/O, and UUIDv7/ULID avoid centralized ID services in event-driven or microservice architectures. For multi-region UUIDv7 generation, keep clocks synchronized with NTP.
- What are alternatives to symfony/uid, and how do I serialize UIDs in Laravel APIs?
- Ramsey\Uuid and Laravel's Str::uuid() are common alternatives, but symfony/uid covers UUID v1 and v3–v8 plus ULIDs under one object-oriented API. For API responses, convert UuidInterface or UlidInterface to RFC 9562, RFC 4122, or Base58 strings and return those strings from API Resources rather than the value object. This keeps JSON payloads stable and avoids vendor lock-in.