getMany($key); } if (! array_key_exists($key, $this->items)) { try { $this->items[$key] = $this->cache->remember($this->cacheKey($key), $this->ttl, function () use ($key) { $_key = $this->keyHandle($key); $settings = Setting::where('key', $_key[0])->firstOrFail(); return Arr::get($settings->value, $_key[1]); }); } catch (ModelNotFoundException $e) { return $default; } catch (Throwable $th) { return $default; } } return $this->items[$key]; } /** * @param array $keys * @return array */ public function getMany(array $keys) { $settings = []; foreach ($keys as $key => $default) { if (is_numeric($key)) { [$key, $default] = [$default, null]; } $settings[$key] = $this->get($key, $default); } return $settings; } /** * @param array|string $key * @param mixed $value * @return void */ public function set($key, $value = null) { $keys = is_array($key) ? $key : [$key => $value]; foreach ($keys as $key => $value) { $_key = $this->keyHandle($key); Setting::where('key', $_key[0])->update(['value->'.$_key[1] => $value]); $this->cleanCache($key); } } /** * @param string $key * @return void */ public function cleanCache(string $key): void { unset($this->items[$key]); $this->cache->forget($this->cacheKey($key)); } /** * @param string $key * @return string */ protected function cacheKey(string $key): string { return "settings.{$key}"; } protected function keyHandle(string $key) { return explode('.', $key); } }