Refactoring of PIREP submission and field code #146

This commit is contained in:
Nabeel Shahzad
2018-01-23 15:48:30 -06:00
parent 341424ad7e
commit f9efa81bb4
19 changed files with 191 additions and 147 deletions

View File

@@ -14,6 +14,7 @@ class PirepField extends BaseModel
public $fillable = [
'name',
'slug',
'required',
];
@@ -24,4 +25,30 @@ class PirepField extends BaseModel
public static $rules = [
'name' => 'required',
];
/**
* Create/update the field slug
*/
protected static function boot()
{
parent::boot();
/**
* On creation
*/
static::creating(function (PirepField $model) {
if (!empty($model->slug)) {
$model->slug = str_slug($model->name);
}
});
/**
* When updating
*/
static::updating(function(PirepField $model) {
if (!empty($model->slug)) {
$model->slug = str_slug($model->name);
}
});
}
}