Files
Epicnabbo-Catalogus-Updated…/Updated_Cms/app/Services/SettingsService.php
T
2026-01-07 19:32:43 +01:00

35 lines
941 B
PHP

<?php
namespace App\Services;
use App\Models\Miscellaneous\WebsiteSetting;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Schema;
use Throwable;
class SettingsService
{
public ?Collection $settings;
public function __construct()
{
try {
Cache::remember('website_settings', now()->addMinutes(5), fn () => Schema::hasTable('website_settings') ? WebsiteSetting::all()->pluck('value', 'key') : collect());
$this->settings = Cache::get('website_settings');
} catch (Throwable) {
$this->settings = collect();
}
}
public function getOrDefault(string $settingName, ?string $default = null): string
{
if (! $this->settings instanceof \Illuminate\Support\Collection) {
return (string) $default;
}
return (string) $this->settings->get($settingName, $default);
}
}