* @version 1.0 * */ class System { private $cacheKey = 'sys_config'; public function __construct() { } public function getCoufig($key=null) { $config = Cache::get($this->cacheKey); if($config){ if($key){ $data = isset($config[$key]) ? $config[$key] : ''; }else{ $data = $config; } }else { $obj = new SysConfigModel(); if ($key) { $data = $obj->select("value")->where("key", $key)->first(); if ($data) { $data = $data->value; } } else { $data = $obj->pluck('value', 'key'); } } return $data; } public function saveConfig($data) { $obj = new SysConfigModel(); foreach($data as $key=>$val) { $objVal = $obj->find($key); if ($objVal){ $objVal->value = $val; $objVal->save(); }else{ $obj->create(['key' => $key,'value'=>$val]); } } $config = $obj->lists('value', 'key')->toArray(); Cache::forever($this->cacheKey, $config); return true; } }