Skip to content

scopeFindSimilarSlugs

Shipu Ahamed edited this page Sep 3, 2016 · 1 revision

scopeFindSimilarSlugs

/**
 * Query scope for finding "similar" slugs, used to determine uniqueness.
 *
 * @param \Illuminate\Database\Eloquent\Builder $query
 * @param \Illuminate\Database\Eloquent\Model $model
 * @param string $attribute
 * @param array $config
 * @param string $slug
 * @return \Illuminate\Database\Eloquent\Builder
 */
public function scopeFindSimilarSlugs(Builder $query, Model $model, $attribute, $config, $slug)
{
    ...
}

This is the default scope for finding "similar" slugs for a model. Basically, we look for existing slugs that are the same as the $slug argument, or that start with $slug plus the separator string. The resulting collection is what is passed to the uniqueSuffix handler.

Generally, this query scope (which is defined in the Sluggable trait) should be left alone. However, you are free to overload it in your models.

Clone this wiki locally