spatie/laravel-sluggable
Automatically generate unique slugs for Eloquent models on create/update. Supports collision suffixes, translatable slugs, and customizable slug options. Includes “self-healing” URLs that keep old links working via slug+id route keys and redirects.
SEO & Content-Driven Features:
spatie/laravel-translatable), aligning with global expansion roadmaps.Developer Productivity:
/posts/my-slug-123), eliminating broken links when content is renamed. Critical for content-heavy apps (e.g., CMS, e-commerce).Scalability & Maintenance:
getSlugOptions() to generate slugs from complex logic (e.g., combining author names + titles) or skip generation for drafts.tenant_id).-1, -2) with UUIDs or hashed values for niche use cases (e.g., analytics tracking).Roadmap Alignment:
/es/mi-articulo, /en/my-article).Look Elsewhere If:
Str::slug() or a custom service.#[Sluggable]) introduce overhead. Benchmark first.getSlugOptions() offers flexibility, but some may prefer raw SQL or custom logic.Consider This Package If:
#[Sluggable] attribute)."This package automates the creation of SEO-friendly URLs for our content (e.g., blog posts, products) by generating clean slugs from titles or custom fields. For example, a post titled ‘How to Build a Laravel App’ becomes /how-to-build-a-laravel-app. Key benefits:
"spatie/laravel-sluggable provides a battle-tested solution for Eloquent slug generation with these advantages:
#[Sluggable] to a model, and it handles uniqueness, collisions, and even self-healing URLs (slug-ID combos like /posts/my-slug-123).#[Sluggable(from: 'title')]).HasSlug trait for advanced logic (closures, scoped uniqueness, custom suffixes)."This package directly supports:
/blog/laravel-tips)./es/mi-articulo).‘By implementing this, we can ensure every post has a clean, SEO-friendly URL automatically—no more manual slug management or broken links when editors rename posts.’"
How can I help you explore Laravel packages today?