mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-07-31 14:16:57 -04:00
60 lines
1.3 KiB
PHP
60 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Modules\Frontend\Services;
|
|
|
|
use Modules\Frontend\Entities\Setting;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class Settings
|
|
{
|
|
public function add($name, $value, $json = null)
|
|
{
|
|
Setting::create([
|
|
'name' => $name,
|
|
'value' => $value,
|
|
'json' => $json,
|
|
]);
|
|
}
|
|
|
|
public function update($name, $value, $json = null)
|
|
{
|
|
$setting = Setting::where('name', $name)->first();
|
|
|
|
if ($setting) {
|
|
$setting->value = $value;
|
|
$setting->json = $json;
|
|
$setting->update();
|
|
|
|
Cache::forget('ott_settings_' . strtolower($name));
|
|
} else {
|
|
$this->add($name, $value, $json);
|
|
}
|
|
}
|
|
|
|
public function getValue($name)
|
|
{
|
|
$setting = Cache::remember('ott_settings_' . strtolower($name), 60 * 60, function () use ($name) {
|
|
return Setting::where('name', $name)->first();
|
|
});
|
|
|
|
if ($setting) {
|
|
return $setting->value;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function getJson($name)
|
|
{
|
|
$setting = Cache::remember('ott_settings_' . strtolower($name), 60 * 60, function () use ($name) {
|
|
return Setting::where('name', $name)->first();
|
|
});
|
|
|
|
if ($setting) {
|
|
return $setting->json;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|