phpvms/app/Models/Airport.php

98 lines
1.9 KiB
PHP
Raw Normal View History

<?php
namespace App\Models;
use Illuminate\Notifications\Notifiable;
/**
* Class Airport
* @package App\Models
*/
class Airport extends BaseModel
{
use Notifiable;
public $table = 'airports';
public $timestamps = false;
public $incrementing = false;
public $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',
2017-07-06 07:48:32 +08:00
'fuel_100ll_cost',
'fuel_jeta_cost',
'fuel_mogas_cost',
];
protected $casts = [
'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',
];
/**
* Validation rules
*/
public static $rules = [
2018-01-01 04:20:52 +08:00
'icao' => 'required',
'name' => 'required',
'lat' => 'required',
'lon' => 'required',
];
/**
* Callbacks
*/
public static function boot()
{
parent::boot();
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)) {
$model->iata = strtoupper(trim($model->iata));
2017-12-31 04:37:10 +08:00
}
$model->icao = strtoupper(trim($model->icao));
$model->id = $model->icao;
});
}
/**
* 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
/**
* @return string
*/
public function getTimezoneAttribute(): string
{
return $this->tz;
}
}