findWhere(['id' => $key], ['type', 'value'])->first(); if(!$setting) { return null; } # cast some types switch($setting->type) { case 'bool': case 'boolean': return (bool) $setting->value; break; case 'date': return Carbon::parse($setting->value); break; case 'int': case 'integer': case 'number': return (int) $setting->value; break; case 'float': return (float) $setting->value; break; default: return $setting->value; } } /** * Update an existing setting with a new value. Doesn't create * a new setting * @param $key * @param $value * @return null */ public function store($key, $value) { $setting = $this->findWhere(['key' => $key], ['id'])->first(); if (!$setting) { return null; } try { $this->update(['value' => $value], $setting->id); } catch (ValidatorException $e) { Log::error($e->getMessage(), $e->getTrace()); } return $value; } }