spatie/laravel-sluggable
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 with 308 redirects to the canonical URL.
This page documents every argument the #[Sluggable] attribute accepts. For setup, see Generating your first slug. For closures, translatable slugs, findBySlug(), and the other features that need the trait, see Using the HasSlug trait.
fromThe source column. Pass a single column name to slugify its value, or an array of column names to join them with the slug separator before slugification. Defaults to 'name'. See Combining multiple source columns.
toThe column the generated slug is written to. Defaults to 'slug'.
separatorThe character Str::slug uses to join words. Defaults to '-'.
languageLanguage code passed to Str::slug for transliteration of non-ASCII characters. Defaults to 'en'.
maxLengthTruncates the slug before uniqueness resolution runs. Defaults to 250. A uniqueness suffix may push the final value slightly past this limit.
uniqueWhen true (the default), the package appends a numeric suffix (-1, -2, etc.) on collisions so the slug column stays unique. Set to false to allow duplicates. To start the suffix from a different number or always force a suffix, see Tuning the uniqueness suffix.
onCreateWhen true (the default), a slug is generated as the model is first persisted. Set to false to leave the column untouched on create.
onUpdateWhen true (the default), the slug is regenerated whenever the source field changes on an update. Set to false for permalinks that should stay fixed after the initial create.
preventOverwriteWhen true, the package skips slug generation if the destination column already holds a value. Defaults to false. Useful when users provide their own slugs and the package should not stomp on them.
selfHealingEnables self-healing route keys. Defaults to false. Requires the HasSlug trait on the same class. See Self-healing URLs.
selfHealingSeparatorThe string placed between the slug and the identifier in the self-healing route key. Defaults to '-'. See Self-healing URLs.
How can I help you explore Laravel packages today?