October\Rain\Database\Traits\Sluggable

Overview

Sluggable trait performs automatic slug generation for new models


Public Methods

public getSluggableSeparator()

public getSluggableSeparator(): string 

getSluggableSeparator is an override for the default slug separator.

public initializeSluggable()

public initializeSluggable(): void

initializeSluggable trait for a model.

public setSluggedValue()

public setSluggedValue(
    string $slugAttribute,
    mixed $sourceAttributes,
    int $maxLength = 175
): string 

setSluggedValue sets a single slug attribute value, using source attributes to generate the slug from and a maximum length for the slug not including the counter. Source attributes support dotted notation for relations.

public slugAttributes()

public slugAttributes(): void 

slugAttributes adds slug attributes to the dataset, used before saving.

Protected Methods

protected getSluggableSourceAttributeValue()

protected getSluggableSourceAttributeValue($key): mixed 

getSluggableSourceAttributeValue using dotted notation. Eg: author.name

protected getSluggableUniqueAttributeValue()

protected getSluggableUniqueAttributeValue(
    string $name,
    mixed $value
): string 

getSluggableUniqueAttributeValue ensures a unique attribute value, if the value is already used a counter suffix is added. Returns a safe value that is unique.

protected newSluggableQuery()

protected newSluggableQuery(): Illuminate\Database\Eloquent\Builder 

newSluggableQuery returns a query that excludes the current record if it exists