2017-06-12 00:36:16 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2018-02-07 00:18:22 +08:00
|
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
|
2017-06-12 00:36:16 +08:00
|
|
|
/**
|
|
|
|
* Class Airport
|
|
|
|
* @package App\Models
|
|
|
|
*/
|
2017-12-26 05:19:34 +08:00
|
|
|
class Airport extends BaseModel
|
2017-06-12 00:36:16 +08:00
|
|
|
{
|
2018-02-07 00:18:22 +08:00
|
|
|
use Notifiable;
|
|
|
|
|
2017-06-12 00:36:16 +08:00
|
|
|
public $table = 'airports';
|
2017-12-01 10:28:45 +08:00
|
|
|
public $timestamps = false;
|
2017-12-07 06:07:25 +08:00
|
|
|
public $incrementing = false;
|
2017-06-12 00:36:16 +08:00
|
|
|
|
|
|
|
public $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',
|
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 = [
|
2017-12-21 09:12:39 +08:00
|
|
|
'lat' => 'float',
|
|
|
|
'lon' => 'float',
|
2017-12-31 04:37:10 +08:00
|
|
|
'hub' => 'boolean',
|
2017-12-30 06:56:46 +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-02-07 02:01:55 +08:00
|
|
|
'icao' => 'required',
|
|
|
|
'iata' => 'nullable',
|
|
|
|
'name' => 'required',
|
|
|
|
'location' => 'nullable',
|
|
|
|
'lat' => 'required|numeric',
|
|
|
|
'lon' => 'required|numeric',
|
2017-06-12 00:36:16 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
2018-01-04 12:04:51 +08:00
|
|
|
* Callbacks
|
2017-06-12 00:36:16 +08:00
|
|
|
*/
|
2018-02-07 00:18:22 +08:00
|
|
|
public static function boot()
|
2017-12-21 01:28:21 +08:00
|
|
|
{
|
2017-12-01 10:28:45 +08:00
|
|
|
parent::boot();
|
2018-02-07 00:18:22 +08:00
|
|
|
|
|
|
|
static::creating(function ($model) {
|
|
|
|
if(filled($model->iata)) {
|
|
|
|
$model->iata = strtoupper(trim($model->iata));
|
|
|
|
}
|
|
|
|
|
|
|
|
$model->icao = strtoupper(trim($model->icao));
|
|
|
|
$model->id = $model->icao;
|
|
|
|
});
|
|
|
|
|
|
|
|
static::updating(function($model) {
|
|
|
|
if (filled($model->iata)) {
|
2018-01-04 12:04:51 +08:00
|
|
|
$model->iata = strtoupper(trim($model->iata));
|
2017-12-31 04:37:10 +08:00
|
|
|
}
|
|
|
|
|
2018-01-04 12:04:51 +08:00
|
|
|
$model->icao = strtoupper(trim($model->icao));
|
2017-12-01 10:28:45 +08:00
|
|
|
$model->id = $model->icao;
|
|
|
|
});
|
2017-06-12 00:36:16 +08:00
|
|
|
}
|
2017-12-21 01:28:21 +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
|
|
|
|
*/
|
|
|
|
public function setIataAttribute($iata)
|
|
|
|
{
|
|
|
|
$iata = strtoupper($iata);
|
|
|
|
$this->attributes['iata'] = $iata;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-21 01:28:21 +08:00
|
|
|
/**
|
|
|
|
* Return full name like:
|
|
|
|
* KJFK - John F Kennedy
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getFullNameAttribute(): string
|
|
|
|
{
|
|
|
|
return $this->icao . ' - ' . $this->name;
|
|
|
|
}
|
2018-02-07 00:33:39 +08:00
|
|
|
|
|
|
|
/**
|
2018-02-07 01:02:40 +08:00
|
|
|
* Shorthand for getting the timezone
|
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-02-07 00:59:31 +08:00
|
|
|
return $this->timezone;
|
2018-02-07 00:33:39 +08:00
|
|
|
}
|
2018-02-07 01:02:40 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shorthand for setting the timezone
|
|
|
|
* @param $value
|
|
|
|
*/
|
|
|
|
public function setTzAttribute($value)
|
|
|
|
{
|
|
|
|
$this->attributes['timezone'] = $value;
|
|
|
|
}
|
2017-06-12 00:36:16 +08:00
|
|
|
}
|