Add configurable system settings service
This commit is contained in:
35
app/Services/System/SystemSettingService.php
Normal file
35
app/Services/System/SystemSettingService.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\System;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class SystemSettingService
|
||||
{
|
||||
/**
|
||||
* Ambil semua konfigurasi sistem dengan struktur terkelompok.
|
||||
*/
|
||||
public function all(): array
|
||||
{
|
||||
return config('system', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ambil satu nilai konfigurasi dengan dukungan dot notation.
|
||||
*/
|
||||
public function get(string $key, mixed $default = null): mixed
|
||||
{
|
||||
return Arr::get($this->all(), $key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set konfigurasi secara runtime tanpa menyentuh database.
|
||||
*/
|
||||
public function set(string $key, mixed $value): void
|
||||
{
|
||||
$settings = $this->all();
|
||||
Arr::set($settings, $key, $value);
|
||||
|
||||
config(['system' => $settings]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user