guava/sqids-for-laravel
Generate short, YouTube-style unique IDs from numbers in Laravel. This package wraps Sqids with a facade, configuration, validation rules, and Eloquent helpers so you can encode and decode IDs cleanly across your app.
/orders/1042 or /orders/k3Rt9z in URLs, APIs, and emails. This package makes "clean, non-sequential-looking URLs" a cheap, reversible feature choice rather than a data-model overhaul.HasSqids trait, validation rule) is a reasonable buy if the maintenance and supply-chain profile are acceptable.encode([$tenantId, $orderId])), and cleaner API resource IDs — features that would otherwise need custom encoding work or a UUID/ULID migration.getRouteKey()) rather than replacing primary keys. Foreign keys stay numeric, no data migration, and the change is reversible — the cheaper and lower-risk product choice.Consider it when:
illuminate/* constraints with no config or trait signature changes.Look elsewhere when:
signed middleware or a real token scheme, and never use it for authorization.min_length are enough to reverse them.sqids/sqids library.min_length invalidates every previously issued ID (emails, bookmarks, third-party callbacks), so environments where that value is not effectively immutable are a poor fit.For executives: This is a small, low-cost Laravel integration that lets us ship short, clean, non-sequential public IDs — /orders/k3Rt9z instead of /orders/1042 — without building or maintaining custom encoding logic. It supports obvious product wins: tidier URLs, less exposure of internal database numbering, and faster delivery of shareable-link and public-reference features. The 1.2.0 release adds Laravel 12 support, so it stays viable through our framework upgrade rather than becoming migration debt. Cost is a targeted dependency with a narrow responsibility and negligible runtime overhead (CPU-local, no extra DB or network hops). One thing to be explicit about at leadership level: this is a UX and obfuscation utility, not a security control. Encoded IDs can be decoded by anyone who knows the configuration, so access to sensitive records must continue to be enforced by our authorization layer — we should not let "the ID looks random" be mistaken for "the record is protected." Second caveat: this is a small, community-maintained package, so we pin it, keep it in the dependency inventory, and retain a low-cost fallback.
For engineering: Buy over build. The package is a thin Laravel wrapper over Sqids — facade, publishable config (alphabet, min_length, blocklist), auto-discovered provider, a HasSqids trait for model keys and route binding, and a validation rule. That's roughly the code we'd otherwise write and then own. Adoption path is low-risk: pin ^1.2, confirm Composer constraints against our Laravel/PHP matrix (1.1.x will not resolve on Laravel 12), spike one low-risk endpoint, encode at the API/resource boundary rather than in model accessors, validate and decode inbound sqids, and keep authorization independent of ID format. Watch four things: (1) decode() returns an array and returns [] on invalid input — treat that as a 404, never pass it to find(); (2) config drift across environments, since config:cache bakes in the alphabet and changing it later is a breaking change for every issued ID; (3) the package is community-maintained with zero dependents, so pin it and keep a fallback plan to call the underlying Sqids library directly; (4) switching route IDs is a public API contract change — plan dual read paths, updated route-model binding, and refreshed API docs/OpenAPI schemas (ID becomes a string) before broad rollout. Ongoing maintenance is essentially dependency bumps.
How can I help you explore Laravel packages today?