phpvms/app/Models/Airport.php

131 lines
2.9 KiB
PHP
Raw Normal View History

<?php
namespace App\Models;
use App\Contracts\Model;
use App\Models\Traits\ExpensableTrait;
use App\Models\Traits\FilesTrait;
/**
* Class Airport
2018-08-27 00:40:04 +08:00
*
* @property string id
* @property string iata
* @property string icao
2018-05-05 02:59:47 +08:00
* @property string name
* @property string full_name
2018-05-05 02:59:47 +08:00
* @property string location
* @property string country
* @property string timezone
* @property float ground_handling_cost
* @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
*/
class Airport extends Model
{
use ExpensableTrait;
use FilesTrait;
public $table = 'airports';
protected $keyType = 'string';
public $incrementing = false;
public $timestamps = false;
2018-03-21 08:40:19 +08:00
protected $fillable = [
'id',
2017-12-31 04:37:10 +08:00
'iata',
2017-07-06 07:48:32 +08:00
'icao',
'name',
'location',
'country',
'lat',
'lon',
2017-12-31 04:37:10 +08:00
'hub',
'timezone',
'ground_handling_cost',
2017-07-06 07:48:32 +08:00
'fuel_100ll_cost',
'fuel_jeta_cost',
'fuel_mogas_cost',
];
protected $casts = [
'lat' => 'float',
'lon' => 'float',
'hub' => 'boolean',
'ground_handling_cost' => 'float',
'fuel_100ll_cost' => 'float',
'fuel_jeta_cost' => 'float',
'fuel_mogas_cost' => 'float',
];
/**
* Validation rules
*/
public static $rules = [
'icao' => 'required',
'iata' => 'sometimes|nullable',
'name' => 'required',
'location' => 'sometimes',
'lat' => 'required|numeric',
'lon' => 'required|numeric',
'ground_handling_cost' => 'nullable|numeric',
'fuel_100ll_cost' => 'nullable|numeric',
'fuel_jeta_cost' => 'nullable|numeric',
'fuel_mogas_cost' => 'nullable|numeric',
];
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): void
2018-02-07 02:01:55 +08:00
{
$iata = strtoupper($iata);
$this->attributes['iata'] = $iata;
}
/**
* Return full name like:
* KJFK - John F Kennedy
2018-08-27 00:40:04 +08:00
*
* @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-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
{
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
*/
public function setTzAttribute($value): void
2018-02-07 01:02:40 +08:00
{
$this->attributes['timezone'] = $value;
}
}