2017-06-12 00:36:16 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\Model;
|
2018-03-08 22:51:36 +08:00
|
|
|
use App\Models\Traits\ExpensableTrait;
|
2018-04-02 07:02:12 +08:00
|
|
|
use App\Models\Traits\FilesTrait;
|
2018-02-07 00:18:22 +08:00
|
|
|
|
2017-06-12 00:36:16 +08:00
|
|
|
/**
|
|
|
|
* Class Airport
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-19 09:37:35 +08:00
|
|
|
* @property string id
|
|
|
|
* @property string iata
|
|
|
|
* @property string icao
|
2018-05-05 02:59:47 +08:00
|
|
|
* @property string name
|
2019-08-05 20:27:53 +08:00
|
|
|
* @property string full_name
|
2018-05-05 02:59:47 +08:00
|
|
|
* @property string location
|
|
|
|
* @property string country
|
|
|
|
* @property string timezone
|
2018-03-20 09:50:40 +08:00
|
|
|
* @property float ground_handling_cost
|
2019-07-23 20:41:20 +08:00
|
|
|
* @property float fuel_100ll_cost
|
|
|
|
* @property float fuel_jeta_cost
|
|
|
|
* @property float fuel_mogas_cost
|
2018-05-05 02:59:47 +08:00
|
|
|
* @property float lat
|
|
|
|
* @property float lon
|
2017-06-12 00:36:16 +08:00
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
class Airport extends Model
|
2017-06-12 00:36:16 +08:00
|
|
|
{
|
2018-03-08 22:51:36 +08:00
|
|
|
use ExpensableTrait;
|
2018-04-02 07:02:12 +08:00
|
|
|
use FilesTrait;
|
2018-02-07 00:18:22 +08:00
|
|
|
|
2017-06-12 00:36:16 +08:00
|
|
|
public $table = 'airports';
|
2019-09-13 20:05:02 +08:00
|
|
|
|
|
|
|
protected $keyType = 'string';
|
2017-12-07 06:07:25 +08:00
|
|
|
public $incrementing = false;
|
2019-09-13 20:05:02 +08:00
|
|
|
public $timestamps = false;
|
2017-06-12 00:36:16 +08:00
|
|
|
|
2018-03-21 08:40:19 +08:00
|
|
|
protected $fillable = [
|
2017-12-01 10:28:45 +08:00
|
|
|
'id',
|
2017-12-31 04:37:10 +08:00
|
|
|
'iata',
|
2017-07-06 07:48:32 +08:00
|
|
|
'icao',
|
|
|
|
'name',
|
|
|
|
'location',
|
2018-01-04 05:41:21 +08:00
|
|
|
'country',
|
2017-07-08 05:15:03 +08:00
|
|
|
'lat',
|
|
|
|
'lon',
|
2017-12-31 04:37:10 +08:00
|
|
|
'hub',
|
2017-12-07 06:07:25 +08:00
|
|
|
'timezone',
|
2018-02-24 05:48:50 +08:00
|
|
|
'ground_handling_cost',
|
2017-07-06 07:48:32 +08:00
|
|
|
'fuel_100ll_cost',
|
|
|
|
'fuel_jeta_cost',
|
|
|
|
'fuel_mogas_cost',
|
2017-06-12 00:36:16 +08:00
|
|
|
];
|
|
|
|
|
2017-12-07 06:07:25 +08:00
|
|
|
protected $casts = [
|
2018-03-20 09:50:40 +08:00
|
|
|
'lat' => 'float',
|
|
|
|
'lon' => 'float',
|
|
|
|
'hub' => 'boolean',
|
2018-02-24 05:48:50 +08:00
|
|
|
'ground_handling_cost' => 'float',
|
2018-03-20 09:50:40 +08:00
|
|
|
'fuel_100ll_cost' => 'float',
|
|
|
|
'fuel_jeta_cost' => 'float',
|
|
|
|
'fuel_mogas_cost' => 'float',
|
2017-12-07 06:07:25 +08:00
|
|
|
];
|
2017-12-21 01:28:21 +08:00
|
|
|
|
2017-06-12 00:36:16 +08:00
|
|
|
/**
|
2017-12-01 10:28:45 +08:00
|
|
|
* Validation rules
|
2017-06-12 00:36:16 +08:00
|
|
|
*/
|
2017-12-01 10:28:45 +08:00
|
|
|
public static $rules = [
|
2018-03-20 09:50:40 +08:00
|
|
|
'icao' => 'required',
|
|
|
|
'iata' => 'nullable',
|
|
|
|
'name' => 'required',
|
|
|
|
'location' => 'nullable',
|
|
|
|
'lat' => 'required|numeric',
|
|
|
|
'lon' => 'required|numeric',
|
|
|
|
'ground_handling_cost' => 'nullable|numeric',
|
2019-07-23 20:41:20 +08:00
|
|
|
'fuel_100ll_cost' => 'nullable|numeric',
|
|
|
|
'fuel_jeta_cost' => 'nullable|numeric',
|
|
|
|
'fuel_mogas_cost' => 'nullable|numeric',
|
2017-06-12 00:36:16 +08:00
|
|
|
];
|
|
|
|
|
2018-02-07 02:01:55 +08:00
|
|
|
/**
|
|
|
|
* @param $icao
|
|
|
|
*/
|
|
|
|
public function setIcaoAttribute($icao)
|
|
|
|
{
|
|
|
|
$icao = strtoupper($icao);
|
|
|
|
$this->attributes['id'] = $icao;
|
|
|
|
$this->attributes['icao'] = $icao;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $iata
|
|
|
|
*/
|
2018-03-19 09:37:35 +08:00
|
|
|
public function setIataAttribute($iata): void
|
2018-02-07 02:01:55 +08:00
|
|
|
{
|
|
|
|
$iata = strtoupper($iata);
|
|
|
|
$this->attributes['iata'] = $iata;
|
|
|
|
}
|
|
|
|
|
2017-12-21 01:28:21 +08:00
|
|
|
/**
|
|
|
|
* Return full name like:
|
|
|
|
* KJFK - John F Kennedy
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2017-12-21 01:28:21 +08:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getFullNameAttribute(): string
|
|
|
|
{
|
2018-03-20 09:50:40 +08:00
|
|
|
return $this->icao.' - '.$this->name;
|
2017-12-21 01:28:21 +08:00
|
|
|
}
|
2018-02-07 00:33:39 +08:00
|
|
|
|
|
|
|
/**
|
2018-02-07 01:02:40 +08:00
|
|
|
* Shorthand for getting the timezone
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-02-07 00:33:39 +08:00
|
|
|
* @return string
|
|
|
|
*/
|
2018-02-07 00:59:31 +08:00
|
|
|
public function getTzAttribute(): string
|
2018-02-07 00:33:39 +08:00
|
|
|
{
|
2018-03-19 09:37:35 +08:00
|
|
|
return $this->attributes['timezone'];
|
2018-02-07 00:33:39 +08:00
|
|
|
}
|
2018-02-07 01:02:40 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shorthand for setting the timezone
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-02-07 01:02:40 +08:00
|
|
|
* @param $value
|
|
|
|
*/
|
2018-03-19 09:37:35 +08:00
|
|
|
public function setTzAttribute($value): void
|
2018-02-07 01:02:40 +08:00
|
|
|
{
|
|
|
|
$this->attributes['timezone'] = $value;
|
|
|
|
}
|
2017-06-12 00:36:16 +08:00
|
|
|
}
|