deligoez/laravel-model-hashid
/users/abc123 instead of /users/123).hashid column (if configured) or generates IDs on-the-fly.retrieved, saved) for ID generation/storage. No forced dependencies beyond Laravel core.hashids/hashids under the hood). Benchmark for high-throughput systems (e.g., >10K IDs/sec).| Risk Area | Mitigation Strategy |
|---|---|
| ID Collisions | Uses cryptographically secure salt and configurable alphabet length (default: 16 chars). Risk negligible for most use cases. |
| Route Binding Failures | Hash IDs are non-sequential; ensure unique constraints in DB if storing them. Fallback to DB ID in edge cases. |
| Migration Complexity | Zero-downtime migration possible if using on-demand generation (no DB schema changes). If storing hash IDs, add column via migration. |
| Version Skew | Package is actively maintained (2026-04-15 release). Monitor for breaking changes in Laravel 10+ compatibility. |
| Security | Hash IDs are not encrypted; avoid using them for sensitive data. Use for opaque identifiers only. |
/users/{hashid} vs. /users/{id}.)| Phase | Steps | Tools/Notes |
|---|---|---|
| Assessment | Audit existing models/routes to identify hash ID candidates (e.g., User, Product). |
Use php artisan route:list to map current ID-based routes. |
| Configuration | Publish package config (php artisan vendor:publish --tag=hashid-config). |
Customize alphabet, salt, length per model. |
| Implementation | Apply trait to target models (e.g., use HashId;). |
Use HasHashId trait or HashId facade for global generation. |
| Storage (Optional) | Add hashid column to DB (if storing IDs). |
Migration: Schema::table('users', fn($table) => $table->string('hashid')->unique()); |
| Routing | Update route definitions to use hash IDs (e.g., Route::get('/users/{user}', ...)). |
Leverage Route::bind() for custom resolution if needed. |
| Caching | Implement Redis caching for generated IDs. | Use HashId::setCache() or middleware to cache responses. |
| Testing | Validate hash ID generation, route binding, and edge cases (e.g., collisions). | Use HashIdTestCase from package or write custom tests. |
| Deployment | Roll out in stages (e.g., non-critical models first). | Monitor CPU usage and ID generation latency. |
composer.json for min/max versions).hashids/hashids (no heavy libraries).retrieved/saved carefully).InternalLog) to test generation.GET /api/users/{hashid}) before web routes.spatie/laravel-hashid).HashId::generate() to test ID creation.php artisan route:list to verify bindings.telescope or laravel-debugbar to profile CPU usage.HashId trait.How can I help you explore Laravel packages today?