<?php  namespace App\Traits;  use App\Models\Tag; use App\Models\TagItem; use DonatelloZa\RakePlus\RakePlus; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Relations\MorphMany;  trait HasTags { 	public static function getTagDelimiter(): string 	{ 		return ' '; 	}  	public static function extractTags(?string $content, ?int $tagCount = null): array 	{ 		$content = preg_replace('/[^A-Za-z0-9]/', ' ', strip_tags($content ?? ''));  		$keywords = array_filter(RakePlus::create($content)->sortByScore()->keywords());  		return array_slice($keywords, 0, $tagCount ?? 5); 	}  	protected static function bootHasTags(): void 	{ 		static::deleting(static function (object $model): void { 			$model->tags->each(static function (TagItem $item): void { 				$item->delete(); 			}); 		});  		static::deleted(static function (object $model): void { 			Tag::doesntHave('items') 				->get() 				->each(static function (Tag $item): void { 					$item->delete(); 				}); 		}); 	}  	public function tags(): MorphMany{}  	public function syncTagsByName(string|array|null $tags = null): self{}  	public function scopeSearchByTag(Builder $query, ?string $search = null): Builder{}  	public function scopeSearchByTagIds(Builder $query, ?array $tags = []): Builder{} }