From 4108b8f90b11a333b66247af2a463f55d63f0b33 Mon Sep 17 00:00:00 2001 From: Jack Grayson Date: Thu, 18 May 2017 22:58:44 -0700 Subject: [PATCH] Ensure that slug is always nonempty Fixes #119 --- app/Traits/SlugTrait.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/Traits/SlugTrait.php b/app/Traits/SlugTrait.php index c9c193dd..f290324e 100644 --- a/app/Traits/SlugTrait.php +++ b/app/Traits/SlugTrait.php @@ -26,7 +26,15 @@ trait SlugTrait { public function setTitleAttribute($value) { - $this->slug = Str::slug($value); + $this->slug = self::makeNonemptySlug($value); $this->attributes['title'] = $value; } + + private static function makeNonemptySlug($title) { + $slug = Str::slug($title); + if ($slug === '') { + $slug = '-'; + } + return $slug; + } }