phpvms/app/Models/Airport.php

119 lines
2.6 KiB
PHP
Raw Normal View History

<?php
namespace App\Models;
use App\Interfaces\Model;
use App\Models\Traits\ExpensableTrait;
use App\Models\Traits\FilesTrait;
/**
* Class Airport
* @property string id
* @property string iata
* @property string icao
2018-05-05 02:59:47 +08:00
* @property string name
* @property string location
* @property string country
* @property string timezone
* @property float ground_handling_cost
2018-05-05 02:59:47 +08:00
* @property float lat
* @property float lon
* @package App\Models
*/
class Airport extends Model
{
use ExpensableTrait;
use FilesTrait;
public $table = 'airports';
public $timestamps = false;
public $incrementing = 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' => 'nullable',
'name' => 'required',
'location' => 'nullable',
'lat' => 'required|numeric',
'lon' => 'required|numeric',
'ground_handling_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
* @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
{
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
* @param $value
*/
public function setTzAttribute($value): void
2018-02-07 01:02:40 +08:00
{
$this->attributes['timezone'] = $value;
}
}