codinglabsau/laravel-sluggable
A lightweight Laravel package that adds automatic slug generation to Eloquent models. Point the trait at a source column and it creates unique, customizable, URL-friendly slugs on save, handling duplicates and separators with minimal configuration.
Architecture fit
codinglabsau/laravel-sluggable is a single-purpose Eloquent behaviour package: a HasSlug trait applied to models, backed by a polymorphic slugs table (slug, sluggable_id, sluggable_type) rather than a column on the parent table. This is architecturally clean for our domain layer — no service provider overrides, no global middleware, no opinion on routing beyond an optional Slug model that can resolve route bindings. It composes with existing models instead of requiring base-class inheritance, which keeps it compatible with our current repository/service patterns.
The trade-off is the side-table design: every slug resolution becomes a join or a second query, and slug uniqueness is enforced at the table level. For high-read public routes (product pages, articles) this is the one area needing deliberate design — either an index-backed lookup or an application-level slug cache.
Integration feasibility High. The integration surface is a composer requirement, a published migration, one trait import per model, and an optional route-binding change. No queue workers, no scheduled jobs, no external services. A TPM should expect this to be a one-sprint item including backfill, not a multi-team dependency.
Technical risk Overall low, with four caveats to verify before commit:
composer why-not / dependency-resolution check plus a full test run rather than trusting the note.Key questions
composer.json, and do all target services meet it?slugs migration or schema change between v1.1.0 and v1.1.1?Slug model behave correctly under Laravel 11's binding resolution, and is it covered by the package's CI?Stack fit Strong fit for a conventional Laravel monolith or modular monolith using Eloquent. The trait-based API means adoption can be incremental — one model first, validated, then rolled out — rather than a cross-cutting refactor. It does not fit well if we have a hard requirement for slugs stored inline on the parent table (e.g. for bulk export, reporting joins, or read replicas that cannot tolerate a polymorphic join).
Migration path
^1.1.1 on a feature branch against the current Laravel version; confirm resolution succeeds.slugs table migration; add an explicit index on (slug) and on (sluggable_type, sluggable_id) if not shipped.Compatibility
The package is additive and does not patch framework internals, so it should coexist with other Eloquent extensions. The genuine compatibility question is the Laravel 11 upgrade itself: v1.1.1 is the version that unblocks Laravel 11, which means it is a prerequisite, not a follow-up to the framework upgrade. Pin to ^1.1.1 (not ^1.1.0) to avoid a resolution failure the moment the framework bump lands.
Sequencing Package bump and staging validation → Laravel 11 upgrade → slug backfill → route-binding cutover → redirect map. Do not run framework upgrade and slug generation changes in the same deploy; both touch model hydration and route resolution, and a combined failure is materially harder to bisect.
Maintenance Low ongoing burden. The package is small, MIT-licensed, and has a stable API. Operational hygiene: pin the minor version, record the dependency in the internal approved-package register, and add a dependabot/renovate watch so the next Laravel support bump surfaces automatically rather than being discovered during an upgrade crunch.
Support Community-supported with a single primary maintainer. No vendor SLA. Acceptable for a non-critical presentation-layer concern like URL slugs; the TPM should treat any business-critical URL contract as our responsibility, not the package's — specifically, redirects for changed slugs must be owned internally.
Scaling
The polymorphic slugs table grows one row per slgged record and is read on every slug-routed request. At scale:
slug column is uniquely indexed — without it, lookups degrade to table scans as the table grows.Failure modes
Slug-based binding is used, a framework upgrade can change resolution order and shadow existing explicit bindings. Cover with a route-level test.^1.1.0 on a Laravel 11 branch will block installs; enforce ^1.1.1 in the lockfile.Ramp-up Minimal — an experienced Laravel engineer is productive within a few hours, reading the trait and one migration. The real ramp-up cost is organisational, not technical: agreeing the slug immutability policy and owning the redirect map across teams. Budget a short design decision on that before implementation, since it determines both the schema and the SEO outcome.
How can I help you explore Laravel packages today?