From 96437151c1b50cae1b23a2e67c567915f15d6ac0 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Tue, 16 Jul 2024 09:45:01 +0100 Subject: [PATCH] Refactor sites to allow eloquent storage --- src/Sites/Sites.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Sites/Sites.php b/src/Sites/Sites.php index 96cb35aee9..40c6ac6665 100644 --- a/src/Sites/Sites.php +++ b/src/Sites/Sites.php @@ -127,17 +127,20 @@ public function path(): string protected function getSavedSites() { - $default = [ + return File::exists($sitesPath = $this->path()) + ? YAML::file($sitesPath)->parse() + : $this->getDefaultSite(); + } + + protected function getDefaultSite() + { + return [ 'default' => [ 'name' => '{{ config:app:name }}', 'url' => '/', 'locale' => 'en_US', ], ]; - - return File::exists($sitesPath = $this->path()) - ? YAML::file($sitesPath)->parse() - : $default; } public function save() @@ -146,8 +149,7 @@ public function save() $newSites = $this->getNewSites(); $deletedSites = $this->getDeletedSites(); - // Save to file - File::put($this->path(), YAML::dump($this->config())); + $this->saveToStore(); // Dispatch our tracked `SiteCreated` and `SiteDeleted` events $newSites->each(fn ($site) => SiteCreated::dispatch($site)); @@ -157,6 +159,12 @@ public function save() $this->sites->each(fn ($site) => SiteSaved::dispatch($site)); } + protected function saveToStore() + { + // Save to file + File::put($this->path(), YAML::dump($this->config())); + } + public function blueprint() { $siteFields = [