diff --git a/app/Models/Subfleet.php b/app/Models/Subfleet.php index 2fe39ff6..6d7486f8 100644 --- a/app/Models/Subfleet.php +++ b/app/Models/Subfleet.php @@ -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');