Using slug options | laravel-sluggable-rust | Spatie       

 SPATIE  

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

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-sluggable-rust](https://spatie.be/docs/laravel-sluggable-rust/v1)  Basic-usage  Using slug options

 Version   v1      

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

  Using slug options    
- [ Introduction ](https://spatie.be/docs/laravel-sluggable-rust/v1/introduction)
- [ Requirements ](https://spatie.be/docs/laravel-sluggable-rust/v1/requirements)
- [ Support us ](https://spatie.be/docs/laravel-sluggable-rust/v1/support-us)
- [ Installation and setup ](https://spatie.be/docs/laravel-sluggable-rust/v1/installation-setup)
- [ Translatable slugs ](https://spatie.be/docs/laravel-sluggable-rust/v1/translatable-slugs)
- [ Changelog ](https://spatie.be/docs/laravel-sluggable-rust/v1/changelog)
- [ Questions and issues ](https://spatie.be/docs/laravel-sluggable-rust/v1/questions-issues)
- [ Upgrading ](https://spatie.be/docs/laravel-sluggable-rust/v1/upgrading)
- [ Testing ](https://spatie.be/docs/laravel-sluggable-rust/v1/testing)
- [ Releasing ](https://spatie.be/docs/laravel-sluggable-rust/v1/releasing)

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

- [ Generating your first slug ](https://spatie.be/docs/laravel-sluggable-rust/v1/basic-usage/getting-started)
- [ Using slug options ](https://spatie.be/docs/laravel-sluggable-rust/v1/basic-usage/using-slug-options)
- [ Finding models by slug ](https://spatie.be/docs/laravel-sluggable-rust/v1/basic-usage/finding-models-by-slug)
- [ Self-healing URLs ](https://spatie.be/docs/laravel-sluggable-rust/v1/basic-usage/self-healing-urls)

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

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

 Using slug options
==================

###  On this page 

1. [ Separator and language ](#content-separator-and-language)
2. [ Maximum length ](#content-maximum-length)
3. [ Duplicate slugs ](#content-duplicate-slugs)
4. [ When to generate a slug ](#content-when-to-generate-a-slug)
5. [ Custom slugs ](#content-custom-slugs)
6. [ Regenerate on demand ](#content-regenerate-on-demand)

`SlugOptions` configures the generation rules for each model. Return a fresh options value from the model's `slug_options()` method. The model, its columns, and its hooks remain application-owned.

The destination is selected by `SlugOptions::create(column, setter)`. Both `String` and `Option<String>` columns work. Use `Option<String>` if you need to distinguish a missing slug from an empty string. The default source must be supplied with `generate_slugs_from` or `generate_slugs_using`.

Separator and language
--------------------------------------------------------------------------------------------------------------------------

`using_separator("_")` changes the word separator and uniqueness suffix separator. The default is `-`. Separators must not be empty.

`using_language("de")` selects language-specific transliteration. English is the default. Language and locale spellings such as `de-DE` are normalized. The default generator uses portable-ascii's language maps, then Laravel's `ascii` and `slug_with` helpers. Use `using_transliterator` to supply different rules.

Maximum length
--------------------------------------------------------------------------------------------------

`slugs_should_be_no_longer_than(100)` truncates the source string to 100 Unicode characters before slugification. The default is 250. Transliteration can expand characters and a uniqueness suffix can exceed this limit, so allow room in the database column. A zero limit returns an error.

Duplicate slugs
-----------------------------------------------------------------------------------------------------

`allow_duplicate_slugs()` disables uniqueness checks. By default the first slug has no suffix and collisions receive `-1`, `-2`, and so on. See [Tuning the uniqueness suffix](../advanced-usage/uniqueness).

When to generate a slug
-----------------------------------------------------------------------------------------------------------------------------

`do_not_generate_slugs_on_create()` leaves the destination untouched on creation. `do_not_generate_slugs_on_update()` leaves it untouched on updates.

`prevent_overwrite()` skips generation whenever the destination is non-NULL, including an explicitly stored empty string. A missing `Option<String>` still receives a slug.

`skip_generate_when` takes a callback over the pending model values. Returning true skips that save. Source callbacks and scopes use the same context, which reads typed columns with `context.get(Post::title)`. On creation, database defaults and database-generated identifiers are not available yet.

Custom slugs
--------------------------------------------------------------------------------------------

An explicitly supplied nonempty destination is kept verbatim, including its case and punctuation. Uniqueness still applies. Clearing the destination regenerates it from the source. On an ordinary update where the destination did not change, the package regenerates it from the current source values.

Regenerate on demand
--------------------------------------------------------------------------------------------------------------------

`options.generate_slug(&mut model).await?` forces generation, bypassing skip, create/update, and overwrite settings. It changes the in-memory model only. Persist the generated value through the model's normal update API.

 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)
