🆙 Add fixed cms 🆙

This commit is contained in:
Remco
2026-02-02 19:30:21 +01:00
parent b1a2cab62d
commit b67e0ec2b9
3982 changed files with 193682 additions and 0 deletions
@@ -0,0 +1,62 @@
<?php
namespace App\Services;
use App\Models\Miscellaneous\WebsiteSetting;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Schema;
use Throwable;
class SettingsService
{
private ?\Illuminate\Support\Collection $cachedSettings = null;
protected function settings()
{
if ($this->cachedSettings !== null) {
return $this->cachedSettings;
}
if ($this->isInstallationIncomplete()) {
$this->cachedSettings = $this->fetchSettings();
return $this->cachedSettings;
}
$this->cachedSettings = Cache::rememberForever('website_settings', fn () => $this->fetchSettings());
return $this->cachedSettings;
}
public function getOrDefault(string $key, mixed $default = null): mixed
{
return $this->settings()->get($key, $default);
}
public static function clearCache(): void
{
Cache::forget('website_settings');
}
private function isInstallationIncomplete(): bool
{
try {
return ! app(InstallationService::class)->isComplete();
} catch (Throwable) {
return true;
}
}
private function fetchSettings()
{
try {
if (! Schema::hasTable('website_settings')) {
return collect();
}
return WebsiteSetting::query()->pluck('value', 'key');
} catch (Throwable) {
return collect();
}
}
}