- How do I replace Laravel’s Str::uuid() with Symfony UID in my project?
- Symfony UID is a drop-in replacement. Replace `Str::uuid()` with `Uuid::v7()` (or `Uuid::v4()` for random) and ensure your database uses binary storage (e.g., `uuid-ossp` in PostgreSQL or `BINARY(16)` in MySQL). Eloquent casts and validation rules remain unchanged.
- Which UUID version should I use for Laravel models—v4, v7, or ULID?
- For time-sorted data (e.g., audit logs, event sourcing), use **UUIDv7** (chronological) or **ULID** (human-readable timestamps). Use **UUIDv4** for randomness (e.g., sensitive data). ULID is better for shareable links (BASE58 encoding), while UUIDv7 avoids collisions in high-throughput systems.
- Does Symfony UID work with Laravel’s Eloquent binary storage for UUIDs?
- Yes. Symfony UID supports binary storage out of the box. Configure your migration to use `uuid-ossp` (PostgreSQL) or `BINARY(16)` (MySQL 8+), then use Eloquent’s `Uuid` or `Ulid` casts. This reduces storage overhead by ~50% compared to `CHAR(36)`.
- How do I generate BASE58-encoded ULIDs for shareable links in Laravel?
- Use `Ulid::generate()->toBase58()`. This encodes ULIDs into URL-safe, compact strings (e.g., `01H5Z9XJQ3K8F7V4T2R1`). Works seamlessly with Laravel API resources and validation rules like `Ulid|base58`.
- Will Symfony UID break my existing Laravel 9/10 app if I upgrade to v8.0.9?
- No. Symfony UID v8.0.9 is backward-compatible with Laravel 9/10 (PHP 8.1+). The only change is PHP 8.4+ support for Laravel 11. If you’re on Laravel 9/10, stick with Symfony UID v7.4.x. No API or Eloquent changes are required.
- How do I mock UUIDs in Laravel tests with Symfony UID?
- Use `MockUuidFactory` from the package to generate deterministic UUIDs in tests. For example: `$mockFactory = new MockUuidFactory(); $uuid = $mockFactory->generate();`. This ensures reproducible test IDs without collisions.
- Does Symfony UID support SQLite for UUID/ULID storage?
- Yes, but you’ll need the `pdo_sqlite` extension with UUID/ULID support (e.g., via SQLite extensions like `sqlite3_uuid`). Store UUIDs as `BLOB` and ULIDs as `TEXT`. Symfony UID’s API remains consistent across databases.
- What’s the performance impact of using binary vs. CHAR(36) storage for UUIDs in Laravel?
- Binary storage (`BINARY(16)`) reduces UUID size by ~50% (16 bytes vs. 36 chars) and improves indexing. Benchmarks show ~20–30% faster queries in PostgreSQL/MySQL. For ULIDs, binary storage isn’t natively supported—use `TEXT` with BASE58 encoding for compactness.
- Can I migrate from auto-increment IDs to UUIDs in Laravel without downtime?
- Yes. Use a **two-phase migration**: 1) Add UUID columns (nullable) to existing tables, 2) Backfill UUIDs for new records, then 3) Drop the auto-increment column. Tools like `laravel-scout` or custom scripts can help sync legacy data.
- Are there alternatives to Symfony UID for Laravel UUID/ULID generation?
- Alternatives include `ramsey/uuid` (UUIDs only), `paragonie/ulid` (ULIDs only), or Laravel’s native `Str::uuid()`. However, Symfony UID is the most **feature-complete** option, supporting **all UUID versions (v1/v3–v8), ULIDs, RFC 9562, BASE58, and binary storage**—making it ideal for Laravel’s ecosystem.