Skip to content

Commit

Permalink
Update SeoManager.php
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-to authored May 27, 2023
1 parent 09e24a7 commit e43fe04
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/SeoManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ final class SeoManager implements Stringable

protected array $custom = [];

protected array $persisted = [];

public function __construct()
{
$this->data = $this->cachedByUrl();
Expand Down Expand Up @@ -83,6 +85,10 @@ public function flushCache(string $key = null): void

public function byUrl(): Model|Seo|null
{
if(isset($this->persisted[(string) $this->url()])) {
return $this->persisted[(string) $this->url()];
}

return Seo::query()
->where('url', (string) $this->url())
->first();
Expand All @@ -99,12 +105,12 @@ public function __call(string $name, array $arguments)
$this->custom[$name] = $arguments[0] ?? '';

if ($arguments[1] ?? false) {
Seo::query()->updateOrCreate(
$data = Seo::query()->updateOrCreate(
['url' => (string) $this->url()],
Arr::except($this->custom, ['og']),
);

$this->flushCache();
$this->persisted[$data->url] = $data;
}
}
}
Expand Down

0 comments on commit e43fe04

Please sign in to comment.