Files
FlightsAPI/app/Models/Aircraft.php
T
2026-05-10 22:42:37 +10:00

52 lines
1.1 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
class Aircraft extends Model
{
protected $fillable = [
'designator',
'manufacturer_code',
'model_full_name',
'aircraft_description',
'engine_type',
'engine_count',
'wtc',
];
protected $casts = [
'engine_count' => 'integer',
];
protected $appends = [
'display_name',
'display_name_short'
];
const array IATA_ALIAS_MAP = [
'7S8' => '73H',
'7S9' => '73J'
];
protected function displayName() : Attribute{
return Attribute::make(
get: function () {
return "{$this->manufacturer_code} {$this->model_full_name} ({$this->designator})";
}
);
}
protected function displayNameShort(): Attribute
{
return Attribute::make(
get: function () {
$name = "{$this->manufacturer_code} {$this->model_full_name}";
return trim(preg_replace('/\s*\(.*?\)/', '', $name));
}
);
}
}