Basics
Inherits from Text.
* has the same capabilities
The field depends on the Eloquent model
This field allows you to generate a slug based on the selected field and to save only unique values.
use MoonShine\Laravel\Fields\Slug; Slug::make('Slug')
Slug Generation
Through the from()
method, you can specify which field of the model to generate the slug from, in case of an absence of a value.
from(string $from)
Slug::make('Slug') ->from('title')
Separator
By default, the word separator when generating the slug is -
, and the separator()
method allows you to change this value.
separator(string $separator)
Slug::make('Slug') ->separator('_')
Locale
By default, slug generation takes into account the application's set locale, and the locale()
method allows you to change this behavior for the field.
locale(string $local)
Slug::make('Slug') ->locale('ru')
Unique Values
If you need to save only unique slugs, you should make use of the unique()
method.
unique()
Slug::make('Slug') ->unique()
Dynamic slug
The live()
method allows you to create a dynamic field that will track changes in the source field.
Text::make('Title') ->reactive(),Slug::make('Slug') ->from('title') ->live()
Dynamism is based on reactivity of fields.