Merge pull request #121 from jack126guy/easy-slug-fix

Ensure that slug is always nonempty
This commit is contained in:
Joe Citrine 2017-05-19 19:55:40 +01:00 committed by GitHub
commit 6cc959069f

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