Skip to content

Commit 1c2cffb

Browse files
committed
Remove redundant makeSlugUnique method overriding
1 parent 790f5ba commit 1c2cffb

File tree

1 file changed

+0
-58
lines changed

1 file changed

+0
-58
lines changed

src/app/Models/Traits/SpatieTranslatable/SlugService.php

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -39,62 +39,4 @@ public function slug(Model $model, bool $force = false): bool
3939

4040
return $this->model->isDirty($attributes);
4141
}
42-
43-
/**
44-
* Checks if the slug should be unique, and makes it so if needed.
45-
*
46-
* @param string $slug
47-
* @param array $config
48-
* @param string $attribute
49-
*
50-
* @return string
51-
*/
52-
protected function makeSlugUnique(string $slug, array $config, string $attribute): string
53-
{
54-
if (! $config['unique']) {
55-
return $slug;
56-
}
57-
58-
$separator = $config['separator'];
59-
60-
// find all models where the slug is like the current one
61-
$list = $this->getExistingSlugs($slug, $attribute, $config);
62-
63-
// if ...
64-
// a) the list is empty, or
65-
// b) our slug isn't in the list
66-
// ... we are okay
67-
if (
68-
$list->count() === 0 ||
69-
$list->contains($slug) === false
70-
) {
71-
return $slug;
72-
}
73-
74-
// if our slug is in the list, but
75-
// a) it's for our model, or
76-
// b) it looks like a suffixed version of our slug
77-
// ... we are also okay (use the current slug)
78-
if ($list->has($this->model->getKey())) {
79-
$currentSlug = $list->get($this->model->getKey());
80-
81-
if (
82-
$currentSlug === $slug ||
83-
strpos($currentSlug, $slug) === 0
84-
) {
85-
return $currentSlug;
86-
}
87-
}
88-
89-
$method = $config['uniqueSuffix'];
90-
if ($method === null) {
91-
$suffix = $this->generateSuffix($slug, $separator, $list, $config['firstUniqueSuffix']);
92-
} elseif (is_callable($method)) {
93-
$suffix = call_user_func($method, $slug, $separator, $list);
94-
} else {
95-
throw new \UnexpectedValueException('Sluggable "reserved" for '.get_class($this->model).':'.$attribute.' is not null, an array, or a closure that returns null/array.');
96-
}
97-
98-
return $slug.$separator.$suffix;
99-
}
10042
}

0 commit comments

Comments
 (0)