From 6c4a8bf1a82046cd8c54107e4863430749ff954a Mon Sep 17 00:00:00 2001 From: Francesco Apruzzese Date: Wed, 13 Mar 2024 12:54:20 +0100 Subject: [PATCH] Aggiornato DbConfig.php per gestire sottocchiavi nei dati di configurazione --- src/DbConfig.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/DbConfig.php b/src/DbConfig.php index 787cdee..bbe079f 100644 --- a/src/DbConfig.php +++ b/src/DbConfig.php @@ -16,7 +16,7 @@ class DbConfig */ public static function get(string $key, mixed $default = null): mixed { - [$group, $setting] = static::parseKey($key); + [$group, $setting, $subKey] = static::parseKey($key); $cachename = "db-config.{$group}.{$setting}"; @@ -24,7 +24,7 @@ public static function get(string $key, mixed $default = null): mixed $data = Cache::rememberForever($cachename, fn () => static::fetchConfig($group, $setting)); - $value = data_get($data, $setting, $default); + $value = data_get($data, $subKey, $default); return $value ?? $default; } @@ -74,8 +74,9 @@ protected static function parseKey(string $key): array $keyParts = explode('.', $key); $group = array_shift($keyParts); $setting = $keyParts[0] ?? null; + $subKey = implode('.', $keyParts); - return [$group, $setting]; + return [$group, $setting, $subKey]; } protected static function fetchConfig(string $group, string $setting): array @@ -85,7 +86,7 @@ protected static function fetchConfig(string $group, string $setting): array ->where('key', $setting) ->first(); - if (! $item) { + if (!$item) { return []; }