Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Refactor sites to allow eloquent storage #10461

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/Sites/Sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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));
Expand All @@ -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 = [
Expand Down
Loading