Skip to content

Commit

Permalink
Fix callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
felixgilles committed Aug 7, 2024
1 parent 9056a8c commit c8549b7
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/Traits/HasMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected function seoRobots(): Attribute
{
return Attribute::make(
get: function () {
return IndexFollow::tryFrom(Arr::get($this->{$this->getMetaColumn()}, 'seo_robots', $this->getMetaConfig()->defaultSeoRobots))?->value;
return (IndexFollow::tryFrom(Arr::get($this->{$this->getMetaColumn()}, 'seo_robots')) ?? $this->getMetaConfig()->defaultSeoRobots)->value;
}
);
}
Expand All @@ -68,7 +68,7 @@ protected function seoTitle(): Attribute
{
return Attribute::make(
get: function () {
return Arr::get($this->{$this->getMetaColumn()}, 'seo_title', $this->fallbackMeta($this->getMetaConfig()->fallbackTitle));
return Arr::get($this->{$this->getMetaColumn()}, 'seo_title') ?? $this->fallbackMeta($this->getMetaConfig()->fallbackTitle);
}
);
}
Expand All @@ -77,7 +77,7 @@ protected function seoDescription(): Attribute
{
return Attribute::make(
get: function () {
return Arr::get($this->{$this->getMetaColumn()}, 'seo_description', $this->fallbackMeta($this->getMetaConfig()->fallbackDescription));
return Arr::get($this->{$this->getMetaColumn()}, 'seo_description') ?? $this->fallbackMeta($this->getMetaConfig()->fallbackDescription);
}
);
}
Expand All @@ -95,7 +95,7 @@ protected function ogType(): Attribute
{
return Attribute::make(
get: function () {
return OgType::tryFrom(Arr::get($this->{$this->getMetaColumn()}, 'og_type', $this->getMetaConfig()->defaultOgType->value));
return (OgType::tryFrom(Arr::get($this->{$this->getMetaColumn()}, 'og_type')) ?? $this->getMetaConfig()->defaultOgType)->value;
}
);
}
Expand All @@ -104,7 +104,7 @@ protected function ogTitle(): Attribute
{
return Attribute::make(
get: function () {
return Arr::get($this->{$this->getMetaColumn()}, 'og_title', $this->fallbackMeta($this->getMetaConfig()->fallbackTitle));
return Arr::get($this->{$this->getMetaColumn()}, 'og_title') ?? $this->fallbackMeta($this->getMetaConfig()->fallbackTitle);
}
);
}
Expand All @@ -113,7 +113,7 @@ protected function ogDescription(): Attribute
{
return Attribute::make(
get: function () {
return Arr::get($this->{$this->getMetaColumn()}, 'og_description', $this->fallbackMeta($this->getMetaConfig()->fallbackDescription));
return Arr::get($this->{$this->getMetaColumn()}, 'og_description') ?? $this->fallbackMeta($this->getMetaConfig()->fallbackDescription);
}
);
}
Expand All @@ -122,7 +122,7 @@ protected function ogImage(): Attribute
{
return Attribute::make(
get: function () {
return Arr::get($this->{$this->getMetaColumn()}, 'og_image', $this->fallbackMeta($this->getMetaConfig()->fallbackImage));
return Arr::get($this->{$this->getMetaColumn()}, 'og_image') ?? $this->fallbackMeta($this->getMetaConfig()->fallbackImage);
}
);
}
Expand All @@ -131,6 +131,10 @@ protected function ogImageUrl(): Attribute
{
return Attribute::make(
get: function () {
if ($this->og_image) {
return asset('storage/'.$this->og_image);
}

return $this->fallbackMeta($this->getMetaConfig()->getOgImageUrl);
}
);
Expand Down

0 comments on commit c8549b7

Please sign in to comment.