Files
boursecu_server/app/Services/ConfigService.php
T

34 lines
732 B
PHP

<?php
namespace App\Services;
use App\Models\Setting;
class ConfigService
{
public function Config($name, $default = false)
{
$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);
}
public function UpdateConfig($name, $value)
{
return Setting::updateOrCreate(
['key' => $name],
['value' => $value]
);
}
}