Compare commits

...

2 Commits

2 changed files with 5 additions and 7 deletions

View File

@ -20,16 +20,13 @@ abstract class ModelWithSlug extends Model
public function getSlug(): string public function getSlug(): string
{ {
if ($this->slug === null) {
$this->slug = $this->generateSlug();
}
return $this->slug; return $this->slug;
} }
private function generateSlug(): string public function generateSlug(): string
{ {
$slugSourceGetMethod = 'get' . str_replace('_', '', ucwords(static::$slugSource, '_')); $slugSourceGetMethod = 'get' . str_replace('_', '', ucwords(static::$slugSource, '_'));
return Slugify::create()->slugify($this->$slugSourceGetMethod()); $this->slug = Slugify::create()->slugify($this->$slugSourceGetMethod());
return $this->slug;
} }
} }

View File

@ -125,7 +125,8 @@ class PersistentDataManager implements IPersistentDataManager
} }
} else { } else {
if ($model instanceof ModelWithSlug) { if ($model instanceof ModelWithSlug) {
$modified['slug'] = $this->generateUniqueSlug($model, $modified['slug']); $slug = $model->generateSlug();
$modified['slug'] = $this->generateUniqueSlug($model, $slug);
} }
$modify->fill($modified); $modify->fill($modified);