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

@@ -4,6 +4,8 @@ namespace App\Models;
/**
* Class PirepField
* @property string name
* @property string slug
* @package App\Models
*/
class PirepField extends BaseModel
@@ -25,33 +27,11 @@ class PirepField extends BaseModel
'name' => 'required',
];
/**
* Create/update the field slug
*/
protected static function boot()
{
parent::boot();
/**
* On creation
*/
static::creating(function (PirepField $model) {
$model->slug = str_slug($model->name);
});
/**
* When updating
*/
static::updating(function(PirepField $model) {
$model->slug = str_slug($model->name);
});
}
/**
* When setting the name attribute, also set the slug
* @param $name
*/
public function setNameAttribute($name)
public function setNameAttribute($name): void
{
$this->attributes['name'] = $name;
$this->attributes['slug'] = str_slug($name);