fixup! add class that handles model with slug

This commit is contained in:
Bence Pőcze 2023-05-07 01:34:54 +02:00
parent 45c4206686
commit 769f3818f3
Signed by: bence
GPG Key ID: DC5BD6E95A333E6D

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;
} }
} }