Skip to content

Commit

Permalink
Allow set slug suffix starting number
Browse files Browse the repository at this point in the history
  • Loading branch information
Stass Ve committed Dec 6, 2022
1 parent 7a271d3 commit 8ff11e1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public function getSlugOptions() : SlugOptions
return SlugOptions::create()
->generateSlugsFrom('name')
->saveSlugsTo('slug')
->slugSuffixStartFrom(2);
->startSlugSuffixFrom(2);
}
```

Expand Down
2 changes: 1 addition & 1 deletion src/HasSlug.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected function getSlugSourceStringFromCallable(): string
protected function makeSlugUnique(string $slug): string
{
$originalSlug = $slug;
$i = $this->slugOptions->slugSuffixStartFrom;
$i = $this->slugOptions->startSlugSuffixFrom;

while ($this->otherRecordExistsWithSlug($slug) || $slug === '') {
$slug = $originalSlug.$this->slugOptions->slugSeparator.$i++;
Expand Down
6 changes: 3 additions & 3 deletions src/SlugOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SlugOptions

public array $translatableLocales = [];

public int $slugSuffixStartFrom = 1;
public int $startSlugSuffixFrom = 1;

public static function create(): static
{
Expand Down Expand Up @@ -127,9 +127,9 @@ public function extraScope(callable $callbackMethod): self
return $this;
}

public function slugSuffixStartFrom(int $slugSuffixStartFrom): self
public function startSlugSuffixFrom(int $startSlugSuffixFrom): self
{
$this->slugSuffixStartFrom = max(1, $slugSuffixStartFrom);
$this->startSlugSuffixFrom = max(1, $startSlugSuffixFrom);

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/HasSlugTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public function getSlugOptions(): SlugOptions
$model = new class () extends TestModel {
public function getSlugOptions(): SlugOptions
{
return parent::getSlugOptions()->slugSuffixStartFrom(2);
return parent::getSlugOptions()->startSlugSuffixFrom(2);
}
};

Expand Down

0 comments on commit 8ff11e1

Please sign in to comment.