diff --git a/src/Views/Concerns/WithSeo.php b/src/Views/Concerns/WithSeo.php index b4d11532..b8d47736 100644 --- a/src/Views/Concerns/WithSeo.php +++ b/src/Views/Concerns/WithSeo.php @@ -6,16 +6,23 @@ trait WithSeo { - use SEOTools; - public function bootWithSeo(): void { - if (method_exists(static::class, 'getTitle')) { - $this->seo()->setTitle(static::getTitle()); + SEOMeta::setTitle($this->seoValue('getTitle')); + SEOMeta::setDescription($this->seoValue('getDescription')); + SEOMeta::setRobots($this->seoValue('getRobots')); + } + + protected function seoValue(mixed $value, mixed $default = null): mixed + { + if ($value instanceof Closure) { + return value($value) ?? $default; } - if (method_exists(static::class, 'getDescription')) { - $this->seo()->setDescription(static::getDescription()); + if (method_exists(static::class, $value)) { + return strip_tags($this->$value()); } + + return $default; } }