- How do I install and set up Polyslug for Laravel?
- Install it with composer require pushery/polyslug-for-laravel; the polyslug_slugs migration auto-registers, so no manual publishing step is required. Add the HasPolyslug trait and a #[Polyslug] attribute to each model you want routable. You can scaffold a model with php artisan make:polyslug Page, and a route then becomes Route::polyslug('/pages/{page}', ...). A technical spike is roughly half a day for a standard model.
- Can multiple Eloquent models share a single slug table?
- Yes. Polyslug is polymorphic by design: models opt in through a polymorphic types registry and all slug records live in one polyslug_slugs table, so slug logic is not duplicated per model. Because adoption is per-model, you can migrate incrementally instead of doing a flag-day migration across the whole application.
- How does Route::polyslug() route model binding work?
- Route::polyslug() is a route macro that composes Laravel's SubstituteBindings with the package's canonical middleware. The key design decision is that the route token {slug}_{encodedId} resolves on the encoded ID, not on the slug text, so the slug is decoration that is free to change without breaking binding. URLs carrying a stale slug still resolve and are answered with a 301 redirect to the canonical URL.
- What happens to old URLs when a slug changes?
- Every slug a record has ever held stays in polyslug_slugs with an is_current flag, so previously published URLs keep resolving rather than 404ing. The canonical middleware then issues a 301 to the current URL, preserving inbound links and search ranking. This turns the usual "renaming a published page broke inbound links" defect into a non-event instead of redirect-spreadsheet maintenance.
- How do I keep database IDs out of URLs?
- The public token in the route is an encoded ID, and the IdentityEncoder interface is the explicit swap point for ID obfuscation. The package ships several encoders, and you can bind your own implementation if you need a different scheme. This gives you leak-safe IDs without coupling the rest of the package to a specific obfuscation strategy.
- How does Polyslug handle record merges and identity changes?
- In v0.24.0 the #[Polyslug(identityOf: 'public_id')] option names the column the token was minted from, so a URL carrying a full old ID still resolves after a record merge or re-keying, with the canonical middleware answering 301 to today's token. identitySecond names a second ID column so a {whole id}-{second id} URL resolves to the record both name. Lookups enumerate candidates through the TailTokens::apart() helper and stay on the identity column's index. Treat this identity-resolution path as fresh code and test your consolidation workflows explicitly.
- Does Polyslug support multilingual slugs and hreflang tags?
- Yes. It provides per-locale slugs plus hreflangLinks(), hreflangTags(), sitemapAlternateTags(), and locale-aware canonical redirects, which are the pieces teams usually hand-roll badly. Locale sourcing is configurable, so you decide where the active locale comes from. The canonical redirects stay locale-aware, which matters when the same record has several valid localized URLs.
- How much configuration does Polyslug require?
- The decision surface is wide: roughly 20 attribute options, around 30 config keys, env overrides such as POLYSLUG_BACKFILL_TRIES for queued backfill attempts, reserved words derived from your routes, soft-delete retention, nested scoping, and bulk resolution. Nothing is gratuitous because each option maps to a real failure mode, but a plausible-looking config can be wrong in ways that only surface under tenancy, localization, identity changes, or heavy rename traffic. Start with a minimal config and grow it deliberately as you test those scenarios.
- Can Polyslug isolate draft or multi-tenant content?
- Yes, polyslugResolveQuery() acts as a draft and tenant isolation lever, not just a security control, and the package also supports nested scoping and soft-delete retention. That lets you keep unpublished or tenant-scoped records out of resolution without bolting on a separate query layer. Verify the behavior against your own tenancy model during the spike, since scoping mistakes tend to appear only under real traffic.
- Is Polyslug production-ready and actively maintained?
- The dominant risk is longevity rather than code quality: it is published under a single vendor namespace (pushery), has a small community footprint, and has no visible formal support or upgrade policy. v0.24.0 is a positive cadence signal, but the identity-resolution path in particular is new and should not be treated as battle-tested. The MIT license gives you a fork escape hatch, though a fork means you own maintenance, so weigh it against more widely adopted slug packages if long-term vendor support is a hard requirement.