47 lines
1.0 KiB
PHP
47 lines
1.0 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'
|
|
];
|
|
|
|
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));
|
|
}
|
|
);
|
|
}
|
|
}
|