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.
#[Sluggable] attribute reduces boilerplate for 90% of use cases, while the HasSlug trait provides granular control for edge cases (e.g., dynamic sources, conditional generation).308 redirect (permanent) is semantically correct for canonical URLs.spatie/laravel-translatable) make it adaptable to multilingual or tenant-isolated systems.composer require; migration is optional (slug column can be added post-install). The package auto-discovers models via attributes/traits.slug column.{slug}-{id} instead of {slug}). Existing routes can coexist via conditional logic.unique: true if duplicates are acceptable (e.g., internal tools).extraScope() to limit uniqueness checks to relevant subsets (e.g., by tenant_id).{slug} → 308 to {slug}-{id})..htaccess or a middleware).language option handles non-ASCII characters, but test with your app’s locales (e.g., Cyrillic, CJK).spatie/laravel-translatable)?generateSlug())?laravel-translatable for multilingual apps).actingAs, assertRedirect).Post, Product, Article).#[Sluggable]) for 80% of cases; reserve the trait for complex logic.{slug}-{id}).308 old {slug} to {slug}-{id}).GET and POST routes.Str::slug() result in memory (e.g., Cache::remember).slug column to target tables (e.g., string(255)).composer require spatie/laravel-sluggable.php artisan vendor:publish --tag="sluggable-config".use Spatie\Sluggable\Attributes\Sluggable; and #[Sluggable] to models.use Spatie\Sluggable\HasSlug; and implement getSlugOptions().{slug}-{id} (e.g., Route::get('/posts/{slug}-{id}', ...)).308 from {slug} to {slug}-{id}).assertEquals('hello-world', $post->slug)).composer update).config/sluggable.php).spatie/laravel-translatable (additional maintenance).try-catch around generateSlug()).dd($model->getSlugOptions()) to inspect configuration.php artisan route:list to verify route binding.tail -f storage/logs/laravel.log for slug generation errors.extraScope() to limit checks to relevant records (e.g., by tenant_id).unique: true if duplicates are acceptable (e.g., internal dashboards).laravel-shift/laravel-queues-testbench).How can I help you explore Laravel packages today?