2017-06-09 09:02:52 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\Model;
|
2018-03-06 09:55:48 +08:00
|
|
|
use App\Models\Enums\JournalType;
|
2018-04-03 00:08:38 +08:00
|
|
|
use App\Models\Traits\FilesTrait;
|
2018-03-02 06:20:13 +08:00
|
|
|
use App\Models\Traits\JournalTrait;
|
2021-06-09 05:46:15 +08:00
|
|
|
use Illuminate\Support\Str;
|
2018-03-02 06:20:13 +08:00
|
|
|
|
2017-06-09 09:02:52 +08:00
|
|
|
/**
|
2017-06-20 00:50:25 +08:00
|
|
|
* Class Airline
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-21 08:17:11 +08:00
|
|
|
* @property mixed id
|
2018-03-20 09:50:40 +08:00
|
|
|
* @property string code
|
|
|
|
* @property string icao
|
|
|
|
* @property string iata
|
|
|
|
* @property string name
|
|
|
|
* @property string logo
|
|
|
|
* @property string country
|
2018-03-03 07:29:11 +08:00
|
|
|
* @property Journal journal
|
2017-06-09 09:02:52 +08:00
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
class Airline extends Model
|
2017-06-09 09:02:52 +08:00
|
|
|
{
|
2018-04-03 00:08:38 +08:00
|
|
|
use FilesTrait;
|
2018-03-02 06:20:13 +08:00
|
|
|
use JournalTrait;
|
|
|
|
|
2017-06-09 09:02:52 +08:00
|
|
|
public $table = 'airlines';
|
|
|
|
|
2018-03-06 09:55:48 +08:00
|
|
|
/**
|
|
|
|
* The journal type for the callback
|
|
|
|
*/
|
|
|
|
public $journal_type = JournalType::AIRLINE;
|
|
|
|
|
2018-03-21 08:40:19 +08:00
|
|
|
protected $fillable = [
|
2017-08-16 21:11:39 +08:00
|
|
|
'icao',
|
2017-07-23 12:03:39 +08:00
|
|
|
'iata',
|
2017-06-09 09:02:52 +08:00
|
|
|
'name',
|
2017-08-16 21:11:39 +08:00
|
|
|
'logo',
|
|
|
|
'country',
|
2018-01-04 02:58:38 +08:00
|
|
|
'total_flights',
|
|
|
|
'total_time',
|
2017-07-08 21:09:58 +08:00
|
|
|
'active',
|
2017-06-09 09:02:52 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that should be casted to native types.
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2017-06-09 09:02:52 +08:00
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $casts = [
|
2018-01-04 02:58:38 +08:00
|
|
|
'total_flights' => 'int',
|
|
|
|
'total_time' => 'int',
|
|
|
|
'active' => 'boolean',
|
2017-06-09 09:02:52 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validation rules
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2017-06-09 09:02:52 +08:00
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public static $rules = [
|
2018-03-20 09:50:40 +08:00
|
|
|
'country' => 'nullable',
|
|
|
|
'iata' => 'nullable|max:5',
|
|
|
|
'icao' => 'required|max:5',
|
|
|
|
'logo' => 'nullable',
|
|
|
|
'name' => 'required',
|
2017-06-09 09:02:52 +08:00
|
|
|
];
|
|
|
|
|
2017-08-16 21:11:39 +08:00
|
|
|
/**
|
|
|
|
* For backwards compatibility
|
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
public function getCodeAttribute()
|
|
|
|
{
|
2018-08-27 00:40:04 +08:00
|
|
|
if ($this->iata && $this->iata !== '') {
|
|
|
|
return $this->iata;
|
|
|
|
}
|
|
|
|
return $this->icao;
|
2017-08-16 21:11:39 +08:00
|
|
|
}
|
|
|
|
|
2018-03-19 09:37:35 +08:00
|
|
|
/**
|
|
|
|
* Capitalize the IATA code when set
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-19 09:37:35 +08:00
|
|
|
* @param $iata
|
|
|
|
*/
|
|
|
|
public function setIataAttribute($iata)
|
2018-01-01 04:20:52 +08:00
|
|
|
{
|
2021-06-09 05:49:42 +08:00
|
|
|
$this->attributes['iata'] = Str::upper($iata);
|
2018-03-19 09:37:35 +08:00
|
|
|
}
|
2018-01-01 04:20:52 +08:00
|
|
|
|
2018-03-19 09:37:35 +08:00
|
|
|
/**
|
|
|
|
* Capitalize the ICAO when set
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-19 09:37:35 +08:00
|
|
|
* @param $icao
|
|
|
|
*/
|
|
|
|
public function setIcaoAttribute($icao): void
|
|
|
|
{
|
2021-06-09 05:46:15 +08:00
|
|
|
$this->attributes['icao'] = Str::upper($icao);
|
2018-01-01 04:20:52 +08:00
|
|
|
}
|
2019-11-19 23:06:07 +08:00
|
|
|
|
2021-01-03 21:05:48 +08:00
|
|
|
public function subfleets()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Subfleet::class, 'airline_id');
|
|
|
|
}
|
|
|
|
|
2021-11-02 20:40:50 +08:00
|
|
|
public function aircraft()
|
|
|
|
{
|
|
|
|
return $this->hasManyThrough(Aircraft::class, Subfleet::class);
|
|
|
|
}
|
|
|
|
|
2019-11-19 23:06:07 +08:00
|
|
|
public function flights()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Flight::class, 'airline_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function pireps()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Pirep::class, 'airline_id');
|
|
|
|
}
|
2017-06-09 09:02:52 +08:00
|
|
|
}
|