Move the model callbacks into Observables; reduce caching since it held balances incorrectly

This commit is contained in:
Nabeel Shahzad
2018-03-18 20:37:35 -05:00
parent 6b002f24a8
commit 36ea12e135
25 changed files with 336 additions and 266 deletions

View File

@@ -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);
}
}