format settings key
This commit is contained in:
@@ -17,6 +17,11 @@ class Setting extends BaseModel
|
||||
'description',
|
||||
];
|
||||
|
||||
public static function formatKey($key)
|
||||
{
|
||||
return str_replace('.', '_', strtolower($key));
|
||||
}
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
@@ -26,7 +31,7 @@ class Setting extends BaseModel
|
||||
*/
|
||||
static::creating(function (Setting $model) {
|
||||
if (!empty($model->id)) {
|
||||
$model->id = str_replace('.', '_', strtolower($model->id));
|
||||
$model->id = Setting::formatKey($model->id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class SettingRepository extends BaseRepository implements CacheableInterface
|
||||
*/
|
||||
public function retrieve($key)
|
||||
{
|
||||
$key = str_replace('.', '_', strtolower($key));
|
||||
$key = Setting::formatKey($key);
|
||||
$setting = $this->findWhere(['id' => $key], ['type', 'value'])->first();
|
||||
|
||||
if(!$setting) {
|
||||
@@ -66,7 +66,8 @@ class SettingRepository extends BaseRepository implements CacheableInterface
|
||||
*/
|
||||
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) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user