remove: slugs

This commit is contained in:
Roardom
2023-01-06 15:29:59 -06:00
parent 0b334015a3
commit 54220dcfc8
50 changed files with 105 additions and 1362 deletions
-24
View File
@@ -30,7 +30,6 @@ class Poll extends Model
*/
protected $fillable = [
'title',
'slug',
'multiple_choice',
];
@@ -69,17 +68,6 @@ class Poll extends Model
$this->attributes['title'] = $title;
}
/**
* Create A Poll Title Slug.
*/
public function makeSlugFromTitle($title): string
{
$slug = \strlen((string) $title) > 20 ? \substr(Str::slug($title), 0, 20) : Str::slug($title);
$count = $this->where('slug', 'LIKE', '%'.$slug.'%')->count();
return $count ? \sprintf('%s-%s', $slug, $count) : $slug;
}
/**
* Get Total Votes On A Poll Option.
*/
@@ -92,16 +80,4 @@ class Poll extends Model
return $result;
}
protected static function boot(): void
{
parent::boot();
self::creating(function ($poll) {
if (empty($poll->slug)) {
$poll->slug = $poll->makeSlugFromTitle($poll->title);
}
return true;
});
}
}