danilovl/hashids-bundle
Symfony bundle integrating Hashids for encoding/decoding IDs. Configure salt, alphabet, and minimum hash length. Optional ParamConverter/Request converter automatically decodes route/request parameters so controllers can receive entities by decoded IDs.
hashids/hashids library directly).services.yaml) suggests low coupling with core logic, easing potential Laravel adaptation.hashids/hashids library is PHP-agnostic and works in Laravel.env() or config() caching.spatie/laravel-hashids) for lower friction.hashids/hashids (v5+).HttpFoundation (for ParamConverter emulation) or Laravel’s Illuminate\Http.hashids/hashids directly with custom middleware.Phase 1: Proof of Concept
hashids/hashids via Composer:
composer require hashids/hashids
use Hashids\Hashids;
$hashids = new Hashids('salt', 20);
$encoded = $hashids->encode(123); // "k3WGv"
$decoded = $hashids->decode($encoded); // [123]
min_hash_length).Phase 2: Feature Parity
// app/Http/Middleware/DecodeHashids.php
public function handle(Request $request, Closure $next) {
$hashids = app(Hashids::class);
$param = $request->route('id');
$decoded = $hashids->decode($param);
$request->merge(['id' => $decoded[0]]);
return $next($request);
}
.env:
HASHIDS_SALT=abcdef...
HASHIDS_MIN_LENGTH=20
Phase 3: Bundle Adaptation (Optional)
Symfony\Component\HttpFoundation\Request → Illuminate\Http\Request.services.yaml → Laravel’s config/hashids.php.Route::bind() or middleware.hashids/hashids; middleware/bindings work natively.HttpTests to validate route decoding.| Step | Priority | Effort | Dependencies |
|---|---|---|---|
Install hashids |
High | Low | None |
| Basic encoding | High | Low | hashids |
| Middleware setup | Medium | Medium | Laravel HTTP stack |
| Config extraction | Low | Low | .env support |
| Fork/bundle adapt | Optional | High | Symfony knowledge |
hashids/hashids is the critical dependency.Hashids instance in Laravel’s service container to avoid reinstantiation.| Scenario | Impact | Mitigation |
|---|---|---|
| Invalid hash input | Decoding fails (e.g., null) |
Add validation middleware. |
| Salt exposure | Predictable IDs | Use Laravel’s env() + encryption. |
| Collision on max int | Decoding returns empty array | Validate input ranges. |
| Bundle abandonment | No updates | Fork or switch to spatie/laravel-hashids. |
README.md for your adapted solution.How can I help you explore Laravel packages today?