From a132da44f9e7d2bd92d3a00c6bfd3c1d9e2f83ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Cmit=20Tun=C3=A7?= Date: Thu, 21 May 2026 08:55:21 +0300 Subject: [PATCH] refactor: rename and enhance setting retrieval methods for improved clarity and functionality --- app/Models/Setting.php | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/app/Models/Setting.php b/app/Models/Setting.php index 60b36cf..5961497 100644 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -320,15 +320,24 @@ class Setting extends Model return isset($this->attributes['value']) ? json_decode($this->attributes['value'], true) : []; } + /** + * Find an active setting record by key. + */ + public static function findActiveByKey(string $key): ?self + { + return static::query() + ->where('key', $key) + ->where('is_active', true) + ->first(); + } + /** * Get setting by key */ public static function get(string $key, $default = null) { - $setting = static::where('key', $key) - ->where('is_active', true) - ->first(); - + $setting = static::findActiveByKey($key); + if (!$setting) { return $default; } @@ -380,12 +389,16 @@ class Setting extends Model */ public static function getGroup(string $group): array { - return static::where('group', $group) + return static::query() + ->where('group', $group) ->where('is_active', true) ->pluck('value', 'key') - ->map(function ($value, $key) use ($group) { - $setting = static::where('key', $key)->first(); - return static::castValue($value, $setting->type); + ->map(function ($value, $key) { + $setting = static::findActiveByKey($key); + + return $setting + ? static::castValue($value, $setting->type) + : $value; }) ->toArray(); }