x-laravel/sluggable
x-laravel/sluggable is a Laravel package that simplifies generating URL-friendly slugs for Eloquent models. It automatically creates clean, unique slugs from chosen source fields, helping you build readable routes and SEO-friendly URLs with minimal configuration.
Contracts\HasSlug to your model and use Concerns\Sluggable. Implement the interface method that returns the attribute or attributes the slug is built from.creating/saving hook. Let the trait generate the slug, then use route model binding or whereSlug() / findBySlug() in controllers.HasSlug, use Sluggable, and return a single source attribute for normal slugs or an array for composite slugs.whereSlug() and findBySlug() instead of raw where('slug', ...) so historical slugs resolve during the retention period. Route model binding should also resolve old slugs.Events\SlugChanged after commit for cache invalidation, redirect creation, search indexing, or audit logs. Use the slugChanging / slugChanged model events for model-local behavior.Rules\Slug for format checks and Rules\UniqueSlug when the slug must also avoid reserved history slugs. The slug string alias is convenient but watch for collisions with existing imports.model:prune remove old history rows. Tune retention age carefully: expired history rows stop resolving and stop reserving the slug.UniqueSlug considers reserved slugs, so it can reject a slug that is not currently attached to a record. Surface that clearly in forms, or users will see “taken” for an apparently free slug.SlugChanged is dispatched after commit. Do not assume listeners run inside the same transaction, and avoid duplicating the same side effect in both model observers and the event listener.withoutGlobalScopes() can create collisions that validation did not see; keep bypass usage out of slug creation paths.schedule:run / cron and confirm the configured frequency, age, and chunk size match your table size.slug validation alias is handy but can conflict with existing rule aliases or imports; use the fully qualified rule class in shared validation code.How can I help you explore Laravel packages today?