Using the Sluggable attribute | laravel-sluggable-go | Spatie       

 SPATIE  

  Laravel Sluggable Go 
=======================

spatie.be/open-source

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

 Version   v1      

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

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

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

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

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

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

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

This page maps every argument of PHP's `#[Sluggable]` attribute to Go's `Options[T]`. Go has no PHP attributes. Start with `sluggable.DefaultOptions[Post]("title")`, change the options you need, and return them from your model's `SlugOptions` method.

For setup, see [Generating your first slug](getting-started). For callbacks, translatable slugs, finding models, and other customization, see [Using the HasSlug trait](using-the-has-slug-trait).

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

`From` contains the source columns. Defaults to `[]string{"name"}`. Columns are joined using the slug separator before slugification. Pass names to `DefaultOptions[Post]("first_name", "last_name")` or assign `From` directly. `Source` replaces the columns with a callback.

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

`To` is the column the generated slug is written to. Defaults to `"slug"`.

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

`Separator` is the string used to join words. Defaults to `"-"`.

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

`Language` selects transliteration rules. Defaults to `"en"`. The default action uses Laravel Go's ASCII mappings and handles German umlauts with `"de"`. Laravel Go does not have PHP's full language-dependent transliteration table. Replace `Config.Slugify` when your application needs other rules. An empty language still uses the default ASCII mappings.

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

`MaxLength` truncates the source by Unicode characters before slugification and uniqueness resolution. Defaults to `250`. Transliteration and a uniqueness suffix may push the final value past this limit.

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

Slugs are unique by default. Set `AllowDuplicates = true` to allow duplicates. On a collision the package appends a numeric suffix. See [Tuning the uniqueness suffix](../advanced-usage/uniqueness).

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

Slugs are generated on create by default. Set `DisableOnCreate = true` to leave the column untouched on create.

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

Slugs are generated on update by default. Set `DisableOnUpdate = true` for permalinks that should stay fixed after the initial create.

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

Set `PreventOverwrite = true` to skip a destination that is already non-null. A `*string` distinguishes an unset slug from an explicitly empty slug. With a plain `string`, even the empty value is non-null. For translated slugs, filled locales are preserved while empty locales can be generated.

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

`SelfHealing = true` enables slug-and-primary-key route keys. Use `ResolveRoute` in the handler. Go does not replace Laravel's route binding automatically. See [Self-healing URLs](self-healing-urls).

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

`SelfHealingSeparator` is placed between the slug and the identifier. Defaults to `"-"`. Use `"--"` with UUID identifiers so the parser does not split inside the UUID.

 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)
