Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Sqid

Laravel Sqid Laravel Package

lava83/laravel-sqid

Laravel integration for Sqids, the short unique ID generator. Encode and decode numeric IDs into compact, URL-safe strings, making it easy to use obfuscated route keys, public-facing identifiers, and cleaner links via a simple facade and model support.

Deep Wiki
Context7

lava83/laravel-sqid integrates Sqids into Laravel to turn numeric IDs into short, URL-friendly, non-sequential identifiers. It helps hide database keys in URLs and APIs while keeping encoding reversible for internal lookups.

  • Generate and decode Sqids through a clean Laravel service/facade.
  • Configurable alphabet, minimum length, and blocklist.
  • Ideal for route parameters, public URLs, and API resources.
  • Publishable configuration for app-specific ID formats.
  • Lightweight wrapper around the official Sqids PHP library.
Frequently asked questions about Laravel Sqid
What is lava83/laravel-sqid used for?
It is a Laravel wrapper around Sqids that turns numeric values into short, unique, URL-friendly strings. The main use case is hiding sequential auto-increment database keys so URLs like /users/1 do not expose how many records you have. It also produces compact identifiers that are safe to place in routes, slugs, and API responses.
How do I install lava83/laravel-sqid?
Install it with Composer using composer require lava83/laravel-sqid. Because it ships a Laravel service provider and facade, the package is registered automatically through Laravel package discovery on supported versions. If you disable discovery, register the provider and alias manually in your application config.
How do I encode and decode IDs with the facade?
The package exposes a facade that lets you encode a number into a Sqid and decode a Sqid back into its original number. That makes it straightforward to convert keys when building URLs and to reverse the process when handling incoming requests. Check the package source for the exact method names and signatures before wiring it into your code.
How do I configure the Sqid alphabet or encoding options?
Encoding behaviour is configured through the package's Laravel configuration, so you can adjust options such as the character alphabet used for generated IDs. Any custom configuration should be published and edited in your app's config directory rather than modified inside the vendor folder. Keep the alphabet identical across all environments, because changing it later will invalidate previously generated Sqids.
Are Sqids reversible, and is that a security risk?
Yes, Sqids are reversible by design, so anyone with the same alphabet and settings can decode your identifiers back to numbers. That makes them an obfuscation layer, not encryption, and they should never be used to protect sensitive data. Always enforce authorization checks in your application rather than relying on the identifier being unreadable.
Can I use Sqids for Laravel route model binding?
Route model binding expects the raw primary key by default, so using Sqids usually means overriding resolveRouteBinding on the model or decoding the parameter in middleware. The facade makes the decode step simple: convert the incoming Sqid to an integer and look up the record. This keeps numeric IDs out of your public URLs while preserving normal Eloquent queries.
Does laravel-sqid work with UUIDs or string primary keys?
Sqids encode non-negative integers, so the package is designed for numeric keys such as auto-incrementing big integers. UUIDs and other string identifiers cannot be passed directly into the encoder. For those, you would keep the UUID as the public identifier or hash it with a different approach.
What Laravel and PHP versions does laravel-sqid support?
Version support is defined in the package's composer.json constraints, which is the authoritative source for the minimum PHP and Laravel requirements. Check those constraints before adding it to an existing project, especially on older Laravel releases. Since the integration is a service provider plus facade, it fits the standard Laravel package structure.
Will the same number always produce the same Sqid?
Yes, encoding is deterministic: the same input number and the same configuration always produce the same Sqid. This is useful because URLs remain stable and shareable across requests and deployments. If you change the alphabet or other encoding options, existing Sqids will no longer decode to their original values.
How does laravel-sqid compare to Hashids or hiding IDs another way?
Sqids is the modern successor to Hashids, offering a similar idea of short reversible IDs from integers with an actively maintained specification. laravel-sqid wraps that library in a Laravel service provider and facade so configuration and usage feel native to the framework. Alternatives include UUIDs or ULIDs, which avoid sequential keys entirely but produce much longer identifiers.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect