Skip to content

Commit

Permalink
Add seoValue
Browse files Browse the repository at this point in the history
  • Loading branch information
francoism90 authored Aug 15, 2024
1 parent 4f81c70 commit a9df6ba
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/Views/Concerns/WithSeo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit a9df6ba

Please sign in to comment.