Using the Sluggable attribute | laravel-sluggable | Spatie

 SPATIE

  Laravel Sluggable
====================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-sluggable](https://spatie.be/docs/laravel-sluggable/v4)  Basic-usage  Using the Sluggable attribute

 Version   v4

 Other versions for crawler [v4](https://spatie.be/docs/laravel-sluggable/v4)

  Using the Sluggable attribute
- [ Introduction ](https://spatie.be/docs/laravel-sluggable/v4/introduction)
- [ Requirements ](https://spatie.be/docs/laravel-sluggable/v4/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-sluggable/v4/installation-setup)
- [ Translatable slugs ](https://spatie.be/docs/laravel-sluggable/v4/translatable-slugs)
- [ Laravel Boost skill ](https://spatie.be/docs/laravel-sluggable/v4/laravel-boost-skill)
- [ Changelog ](https://spatie.be/docs/laravel-sluggable/v4/changelog)
- [ Questions and issues ](https://spatie.be/docs/laravel-sluggable/v4/questions-issues)
- [ Support us ](https://spatie.be/docs/laravel-sluggable/v4/support-us)
- [ Upgrading ](https://spatie.be/docs/laravel-sluggable/v4/upgrading)

Basic usage
-----------

- [ Generating your first slug ](https://spatie.be/docs/laravel-sluggable/v4/basic-usage/getting-started)
- [ Using the Sluggable attribute ](https://spatie.be/docs/laravel-sluggable/v4/basic-usage/using-the-attribute)
- [ Using the HasSlug trait ](https://spatie.be/docs/laravel-sluggable/v4/basic-usage/using-the-has-slug-trait)
- [ Finding models by slug ](https://spatie.be/docs/laravel-sluggable/v4/basic-usage/finding-models-by-slug)
- [ Self-healing URLs ](https://spatie.be/docs/laravel-sluggable/v4/basic-usage/self-healing-urls)

Advanced usage
--------------

- [ Combining multiple source columns ](https://spatie.be/docs/laravel-sluggable/v4/advanced-usage/source-fields)
- [ Tuning the uniqueness suffix ](https://spatie.be/docs/laravel-sluggable/v4/advanced-usage/uniqueness)
- [ Overriding the underlying actions ](https://spatie.be/docs/laravel-sluggable/v4/advanced-usage/overriding-actions)

 Using the Sluggable attribute
=============================

This page documents every argument the `#[Sluggable]` attribute accepts. For setup, see [Generating your first slug](/docs/laravel-sluggable/v4/basic-usage/getting-started). For closures, translatable slugs, `findBySlug()`, and the other features that need the trait, see [Using the HasSlug trait](/docs/laravel-sluggable/v4/basic-usage/using-the-has-slug-trait).

`from`
----------------------------------------------------------------------

The 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](/docs/laravel-sluggable/v4/advanced-usage/source-fields).

`to`
----------------------------------------------------------------

The column the generated slug is written to. Defaults to `'slug'`.

`separator`
-------------------------------------------------------------------------------------

The character `Str::slug` uses to join words. Defaults to `'-'`.

`language`
----------------------------------------------------------------------------------

Language code passed to `Str::slug` for transliteration of non-ASCII characters. Defaults to `'en'`.

`maxLength`
-------------------------------------------------------------------------------------

Truncates the slug before uniqueness resolution runs. Defaults to `250`. A uniqueness suffix may push the final value slightly past this limit.

`unique`
----------------------------------------------------------------------------

When `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](/docs/laravel-sluggable/v4/advanced-usage/uniqueness).

`onCreate`
----------------------------------------------------------------------------------

When `true` (the default), a slug is generated as the model is first persisted. Set to `false` to leave the column untouched on create.

`onUpdate`
----------------------------------------------------------------------------------

When `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.

`preventOverwrite`
----------------------------------------------------------------------------------------------------------

When `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.

`selfHealing`
-------------------------------------------------------------------------------------------

Enables self-healing route keys. Defaults to `false`. Requires the `HasSlug` trait on the same class. See [Self-healing URLs](/docs/laravel-sluggable/v4/basic-usage/self-healing-urls).

`selfHealingSeparator`
----------------------------------------------------------------------------------------------------------------------

The string placed between the slug and the identifier in the self-healing route key. Defaults to `'-'`. See [Self-healing URLs](/docs/laravel-sluggable/v4/basic-usage/self-healing-urls).

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
