- Can I use roukmoute/sqids-bundle in a Laravel application?
- Not directly. roukmoute/sqids-bundle is a Symfony bundle that relies on Symfony's dependency injection and configuration tree, so it does not map cleanly to Laravel's service provider and config system. For Laravel, install the underlying sqids/sqids library and register it as a singleton in a service provider, optionally with a facade. This avoids Symfony bundle coupling and keeps the integration small and maintainable.
- What is roukmoute/sqids-bundle used for?
- It integrates Sqids into Symfony to generate short, unique, URL-safe identifiers from sequential numbers and decode them back. You can use it to hide database IDs in URLs without exposing primary keys. It provides an autowired Sqids service plus configuration for alphabet, minimum length, and blocklist. The encode and decode API is minimal and framework-friendly.
- How do I install Sqids in Laravel?
- Install the framework-agnostic sqids/sqids package with Composer, not the Symfony bundle. Then create a Laravel service provider that binds a Sqids instance as a singleton and reads alphabet, minimum length, and blocklist values from config. You can inject the singleton into controllers and services or expose a facade for convenience. This gives you the same encoding behavior without Symfony-specific classes.
- Does roukmoute/sqids-bundle support Laravel 11 or Laravel 12?
- The bundle itself targets Symfony and is not tested or supported as a Laravel package. Laravel 11 and 12 use Symfony 7.x components, while the bundle's v0.10.0 change adds Symfony 8 compatibility, so the change is harmless but not useful for Laravel. For Laravel support, use sqids/sqids directly with a thin service provider. That approach works across supported PHP and Laravel versions.
- How do I configure the Sqids alphabet and minimum length in Laravel?
- With the underlying sqids/sqids library, create a config file such as config/sqids.php that returns alphabet, minLength, and blocklist values. In your service provider, pass those values into the Sqids constructor when binding the singleton. Read them with config('sqids.alphabet') and similar calls so they remain environment-aware. The Symfony bundle's configuration tree is not used in this setup.
- What are the alternatives to roukmoute/sqids-bundle for Laravel?
- The closest alternative is the underlying sqids/sqids PHP library wrapped in a Laravel service provider. You can also use Hashids or Laravel's built-in encryption and signed URLs if you only need opaque or tamper-proof identifiers. Custom encoders are another option when requirements are simple. Prefer framework-agnostic libraries for Laravel to avoid adapting Symfony-specific bundles.
- Is Sqids secure enough to hide database IDs in production?
- Sqids provides obfuscation, not encryption; anyone with the alphabet and settings can decode an ID. Treat encoded values as public identifiers, not secrets, and never rely on them for authorization. Enforce access control on every request and consider signed URLs or encryption when tamper resistance is required. Sqids is suitable for cleaner URLs when combined with proper server-side checks.
- How do I test encode and decode with Sqids in Laravel?
- Write feature or unit tests that resolve the Sqids singleton from the container and assert round-trip encoding. Include edge cases such as zero, large integers, negative inputs, and blocklisted outputs. If you use a facade, test both the container binding and the facade call. Keep alphabet and minimum length in test configuration so assertions remain deterministic.
- What are the maintenance risks of using roukmoute/sqids-bundle?
- The bundle is pre-1.0, has a small maintainer base, and tracks Symfony releases, so minor versions may introduce breaking changes. The v0.10.0 return-type change shows proactive Symfony 8 readiness but adds no new features. For Laravel, the bigger risk is adapting Symfony DI and configuration, not the encode/decode API. Pinning versions and preferring sqids/sqids directly reduces that risk.
- How do I migrate from Hashids to Sqids in Laravel?
- Install sqids/sqids and bind it in a service provider, then replace Hashids encode and decode calls with Sqids equivalents. Existing Hashids values will not decode with Sqids because the algorithms and alphabets differ, so plan a transition for stored or shared identifiers. Regenerate URLs or keep a temporary decoding path for legacy IDs. Test edge cases and update configuration for alphabet, minimum length, and blocklist.