Move the model callbacks into Observables; reduce caching since it held balances incorrectly
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user