format settings key

This commit is contained in:
Nabeel Shahzad
2017-12-31 11:19:18 -06:00
parent 948338d2b6
commit e73440d081
2 changed files with 9 additions and 3 deletions
+6 -1
View File
@@ -17,6 +17,11 @@ class Setting extends BaseModel
'description', 'description',
]; ];
public static function formatKey($key)
{
return str_replace('.', '_', strtolower($key));
}
protected static function boot() protected static function boot()
{ {
parent::boot(); parent::boot();
@@ -26,7 +31,7 @@ class Setting extends BaseModel
*/ */
static::creating(function (Setting $model) { static::creating(function (Setting $model) {
if (!empty($model->id)) { if (!empty($model->id)) {
$model->id = str_replace('.', '_', strtolower($model->id)); $model->id = Setting::formatKey($model->id);
} }
}); });
} }
+3 -2
View File
@@ -28,7 +28,7 @@ class SettingRepository extends BaseRepository implements CacheableInterface
*/ */
public function retrieve($key) public function retrieve($key)
{ {
$key = str_replace('.', '_', strtolower($key)); $key = Setting::formatKey($key);
$setting = $this->findWhere(['id' => $key], ['type', 'value'])->first(); $setting = $this->findWhere(['id' => $key], ['type', 'value'])->first();
if(!$setting) { if(!$setting) {
@@ -66,7 +66,8 @@ class SettingRepository extends BaseRepository implements CacheableInterface
*/ */
public function store($key, $value) public function store($key, $value)
{ {
$setting = $this->findWhere(['key' => $key], ['id'])->first(); $key = Setting::formatKey($key);
$setting = $this->findWhere(['id' => $key], ['id'])->first();
if (!$setting) { if (!$setting) {
return null; return null;
} }