63 lines
1.4 KiB
PHP
63 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class Airline extends Model
|
|
{
|
|
protected $table = 'airlines';
|
|
|
|
protected $fillable = [
|
|
'IATA_code',
|
|
'ICAO_code',
|
|
'name',
|
|
'internal_name',
|
|
'country_id',
|
|
'alliance_id',
|
|
'active',
|
|
'logo',
|
|
];
|
|
|
|
protected $casts = [
|
|
'active' => 'boolean',
|
|
];
|
|
|
|
public $timestamps = false;
|
|
protected $appends = [
|
|
'display_name',
|
|
'logo_url',
|
|
];
|
|
|
|
protected function displayName() : Attribute{
|
|
return Attribute::make(
|
|
get: function () {
|
|
$codes = array_filter([$this->IATA_code, $this->ICAO_code]);
|
|
$codeString = count($codes) ? ' (' . implode('/', $codes) . ')' : '';
|
|
return "{$this->name}{$codeString}";
|
|
}
|
|
);
|
|
}
|
|
|
|
protected function logoUrl() : Attribute{
|
|
return Attribute::make(
|
|
get: function () {
|
|
return config('app.logo_api_url') . "/airline/$this->internal_name/logo/tail";
|
|
}
|
|
);
|
|
}
|
|
|
|
public function alliance(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Alliance::class);
|
|
}
|
|
|
|
public function country(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Country::class);
|
|
}
|
|
}
|