Files
boursecu_server/app/Services/ConfigService.php
T

34 lines
732 B
PHP
Raw Normal View History

2026-05-24 13:56:33 +03:30
<?php
namespace App\Services;
2026-05-24 19:22:09 +03:30
use App\Models\Setting;
2026-05-24 13:56:33 +03:30
class ConfigService
{
2026-05-25 19:42:48 +03:30
public function Config($name, $default = false)
2026-05-24 13:56:33 +03:30
{
2026-05-25 19:42:48 +03:30
$value = Setting::where('key', $name)->value('value');
return $value !== null ? $value : $default;
}
public function ConfigBool(string $name, bool $default = false): bool
{
$value = $this->Config($name, null);
if ($value === null) {
return $default;
}
return in_array(strtolower(trim((string) $value)), ['1', 'true', 'yes', 'on'], true);
2026-05-24 13:56:33 +03:30
}
2026-05-24 19:22:09 +03:30
public function UpdateConfig($name, $value)
2026-05-24 13:56:33 +03:30
{
2026-05-25 19:42:48 +03:30
return Setting::updateOrCreate(
2026-05-24 22:29:43 +03:30
['key' => $name],
['value' => $value]
);
2026-05-24 13:56:33 +03:30
}
2026-05-24 19:22:09 +03:30
}