57 lines
1.2 KiB
PHP
57 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use App\Models\SiteSetting;
|
|
|
|
class Settings
|
|
{
|
|
public static $settings = null;
|
|
|
|
protected static $cacheKey = 'site_settings';
|
|
|
|
public static function __callStatic($key, $arguments)
|
|
{
|
|
return self::get($key);
|
|
}
|
|
|
|
// Load settings from the database
|
|
public static function loadSettings()
|
|
{
|
|
if (self::$settings === null) {
|
|
self::$settings = SiteSetting::all()->pluck('setting_value', 'setting_key')->toArray();
|
|
}
|
|
|
|
}
|
|
|
|
// Get a setting value by key
|
|
public static function get($key, $default = null)
|
|
{
|
|
if (self::$settings === null) {
|
|
self::loadSettings();
|
|
}
|
|
|
|
return self::$settings[$key] ?? $default;
|
|
}
|
|
|
|
// Set a setting value by key
|
|
public static function set($key, $value)
|
|
{
|
|
// Update the database
|
|
SiteSetting::updateOrCreate(['setting_key' => $key], ['setting_value' => $value]);
|
|
|
|
// Update the static property
|
|
if (self::$settings === null) {
|
|
self::loadSettings();
|
|
}
|
|
self::$settings[$key] = $value;
|
|
|
|
}
|
|
|
|
// Clear the settings
|
|
public static function clearSettings()
|
|
{
|
|
self::$settings = null;
|
|
}
|
|
}
|