Ensure that slug is always nonempty

Fixes #119 <https://github.com/Poniverse/Pony.fm/issues/119>
This commit is contained in:
Jack Grayson 2017-05-18 22:58:44 -07:00
parent 2de284963e
commit 4108b8f90b

View file

@ -26,7 +26,15 @@ trait SlugTrait
{ {
public function setTitleAttribute($value) public function setTitleAttribute($value)
{ {
$this->slug = Str::slug($value); $this->slug = self::makeNonemptySlug($value);
$this->attributes['title'] = $value; $this->attributes['title'] = $value;
} }
private static function makeNonemptySlug($title) {
$slug = Str::slug($title);
if ($slug === '') {
$slug = '-';
}
return $slug;
}
} }