π A slug should be allowed to change without breaking the URL.
Take a typical Laravel application:
/articles/1523
Not particularly descriptive. It also exposes a sequential database ID.
Or:
/articles/understanding-laravel-routing
Better for humans, but what happens when the title changes, the content gets translated, or someone shares an outdated URL?
Polyslug for Laravel separates the human-readable slug from the model's identity.
For example:
/articles/understanding-laravel_aB3xK
The slug is editable and language-specific. The encoded identifier remains stable.
Here's what that enables:
π Automatic canonical redirects
Rename an article, product, or page. Old URLs continue resolving to the same model and automatically return a 301 redirect to the current canonical URL.
π Multilingual URLs
Maintain separate slugs for each locale, with canonical URLs and reciprocal hreflang references.
π Opaque identifiers
By default, models receive random, unguessable tokens instead of exposing sequential primary keys. Alternative encoders include Sqids, UUIDs, ULIDs, and custom implementations.
π§© Polymorphic routing
Route different Eloquent models through a shared content registry. Useful for applications with articles, products, pages, and other content types.
βοΈ Flexible URL structures
Use slugs with tokens, token-only URLs, or slug-only URLs. Configure uniqueness per tenant, locale, category, or other scopes.
Polyslug also supports slug history, change events, immutable slugs, and optional integration with laravel/head for canonical tags, Open Graph locales, and indexability metadata.
No manually maintained redirect tables for every renamed article. No dependency on the current slug to identify the underlying model.
Readable URLs for humans. Stable identities for applications.
Laravel 13+, PHP 8.4+, MIT licensed.
https://github.com/pushery/polyslug-for-laravel
GitHubGitHub - pushery/polyslug-for-laravel: Polyslug gives Laravel Eloquent models multilingual, polymorphic, SEO-friendly URLs by combining editable localized slugs with stable opaque IDs, so routes stay resolvable after renames and can self-heal through canonical redirects with hreflang support builtβ¦Polyslug gives Laravel Eloquent models multilingual, polymorphic, SEO-friendly URLs by combining editable localized slugs with stable opaque IDs, so routes stay resolvable after renames and can sel...
1 other commit about this linkcommit 2fdf781