Move the model callbacks into Observables; reduce caching since it held balances incorrectly
This commit is contained in:
@@ -2,6 +2,18 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
/**
|
||||
* Class Setting
|
||||
* @property string id
|
||||
* @property string name
|
||||
* @property string key
|
||||
* @property string value
|
||||
* @property string group
|
||||
* @property string type
|
||||
* @property string options
|
||||
* @property string description
|
||||
* @package App\Models
|
||||
*/
|
||||
class Setting extends BaseModel
|
||||
{
|
||||
public $table = 'settings';
|
||||
@@ -33,29 +45,21 @@ class Setting extends BaseModel
|
||||
}
|
||||
|
||||
/**
|
||||
* Callbacks
|
||||
* Force formatting the key
|
||||
* @param $id
|
||||
*/
|
||||
protected static function boot()
|
||||
public function setIdAttribute($id): void
|
||||
{
|
||||
parent::boot();
|
||||
static::creating(function (Setting $model) {
|
||||
if (!empty($model->id)) {
|
||||
$model->id = Setting::formatKey($model->id);
|
||||
}
|
||||
});
|
||||
$id = strtolower($id);
|
||||
$this->attributes['id'] = self::formatKey($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the casting mechanism
|
||||
* @param string $key
|
||||
* @return mixed|string
|
||||
* Set the key to lowercase
|
||||
* @param $key
|
||||
*/
|
||||
/*protected function getCastType($key)
|
||||
public function setKeyAttribute($key): void
|
||||
{
|
||||
if ($key === 'value' && !empty($this->type)) {
|
||||
return $this->type;
|
||||
} else {
|
||||
return parent::getCastType($key);
|
||||
}
|
||||
}*/
|
||||
$this->attributes['key'] = strtolower($key);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user