#add git monitor
This commit is contained in:
43
app/Services/ConfigService.php
Normal file
43
app/Services/ConfigService.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Config;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class ConfigService
|
||||
{
|
||||
public function get(string $key, mixed $default = null): mixed
|
||||
{
|
||||
$config = Config::query()->where('key', $key)->first();
|
||||
|
||||
return $config?->value ?? $default;
|
||||
}
|
||||
|
||||
public function getNested(string $key, string $path, mixed $default = null): mixed
|
||||
{
|
||||
$value = $this->get($key);
|
||||
|
||||
return Arr::get($value ?? [], $path, $default);
|
||||
}
|
||||
|
||||
public function set(string $key, mixed $value, ?string $description = null): Config
|
||||
{
|
||||
return Config::query()->updateOrCreate(
|
||||
['key' => $key],
|
||||
[
|
||||
'value' => $value,
|
||||
'description' => $description,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function setNested(string $key, string $path, mixed $value, ?string $description = null): Config
|
||||
{
|
||||
$payload = $this->get($key, []);
|
||||
Arr::set($payload, $path, $value);
|
||||
|
||||
return $this->set($key, $payload, $description);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user