. */ namespace App\Traits; use Illuminate\Support\Str; trait SlugTrait { public function setTitleAttribute($value) { $this->slug = self::makeNonemptySlug($value); $this->attributes['title'] = $value; } private static function makeNonemptySlug($title) { $slug = Str::slug($title); if ($slug === '') { $slug = '-'; } return $slug; } }