Make sure the subfleet name doesn't have spaces

This commit is contained in:
Nabeel Shahzad
2018-02-21 20:16:49 -06:00
parent 7872a6a442
commit 1a54aadc19

View File

@@ -39,6 +39,31 @@ class Subfleet extends BaseModel
'type' => 'required',
];
/**
* Modify some fields on the fly. Make sure the subfleet
* names don't have spaces in them.
*/
public static function boot()
{
parent::boot();
static::creating(function ($model) {
if (filled($model->name)) {
$model->name = str_replace(' ', '_', $model->name);
}
});
static::updating(function ($model) {
if (filled($model->name)) {
$model->name = str_replace(' ', '_', $model->name);
}
});
}
/**
* Relationships
*/
public function aircraft()
{
return $this->hasMany(Aircraft::class, 'subfleet_id');