trianity / laravel-sqids
A Hashids / Sqids bridge for Laravel 10, 11, 12 and 13
Requires
- php: >=8.2 <9.0
- ext-bcmath: *
- illuminate/contracts: ^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^10.0|^11.0|^12.0|^13.0
- sqids/sqids: ^0.4.1|^0.5.0
Requires (Dev)
- larastan/larastan: ^2.11|^3.10
- laravel/pint: ^1.29
- orchestra/testbench: ^8.37|^9.17|^10.11|^11.1
- pestphp/pest: ^2.36|^3.8|^4.7
This package is auto-updated.
Last update: 2026-06-28 12:28:08 UTC
README
A small Hashids / Sqids bridge for Laravel. It wraps sqids/sqids and exposes a Laravel service provider and facade.
Sqids generate short, URL-safe IDs from non-negative integers and can decode them back to the original numbers. They are useful for public URLs where exposing database IDs is undesirable. Sqids are not encryption and should not be used for sensitive data.
Requirements
| Laravel | PHP |
|---|---|
| 10.x | 8.2+ |
| 11.x | 8.2+ |
| 12.x | 8.2+ |
| 13.x | 8.3+ |
Laravel 13 requires PHP 8.3 or newer through Laravel's own dependency constraints.
Installation
composer require trianity/laravel-sqids
The package is auto-discovered by Laravel.
Configuration
Publishing the config file is optional:
php artisan vendor:publish --provider="Trianity\Sqids\Providers\PackageServiceProvider"
You can also publish by tag:
php artisan vendor:publish --tag=config-sqids
The published config/sqids.php file contains:
return [ 'minLength' => 12, 'alphabet' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', 'blocklist' => [ // 'word', ], ];
Usage
Use the facade:
use Trianity\Sqids\Facades\Sqids; $id = Sqids::encode([4815162342]); $numbers = Sqids::decode($id);
Use dependency injection:
use Trianity\Sqids\SqidsFactory; final class LinkController { public function show(SqidsFactory $sqids, string $id): array { return $sqids->decode($id); } }
Create a custom instance when you need a different alphabet, minimum length, or blocklist:
use Trianity\Sqids\SqidsFactory; $sqids = new SqidsFactory(minLength: 24); $id = $sqids->encode([1, 2, 3]);
Upgrade From 11.0.2
No application code changes are required when upgrading from 11.0.2.
This release expands Composer constraints for Laravel 12 and Laravel 13, keeps Laravel 10 and Laravel 11 compatibility, removes the static version field from composer.json, and keeps the existing service provider, facade, config keys, and public namespace unchanged.
Recommended upgrade command:
composer require trianity/laravel-sqids:^11.1 -W