phpvms/app/Models/Airport.php
web541 08df20de19 Fixed a few field entries (#116)
* Stopped inheritance errors popping up

* Added fillable fields

These would not save otherwise.

* Added country fillable field

Wouldn’t save when importing from phpvms classic.

* Added more to classic importer

Change arguments to ask in terminal
Fixed table_prefix names in Importer.php

Added the ability to import users from phpvms classic (tested on
simpilot’s 5.5.x) and when importing, it will then reset the user’s
password to a temporary hash and then email it to the user to then
change when they first log in.

* Changes to ImporterService
2018-01-03 15:41:21 -06:00

81 lines
1.6 KiB
PHP

<?php
namespace App\Models;
/**
* Class Airport
* @package App\Models
*/
class Airport extends BaseModel
{
public $table = 'airports';
public $timestamps = false;
public $incrementing = false;
public $fillable = [
'id',
'iata',
'icao',
'name',
'location',
'country',
'lat',
'lon',
'hub',
'timezone',
'fuel_100ll_cost',
'fuel_jeta_cost',
'fuel_mogas_cost',
];
protected $casts = [
'lat' => 'float',
'lon' => 'float',
'hub' => 'boolean',
'fuel_100ll_cost' => 'float',
'fuel_jeta_cost' => 'float',
'fuel_mogas_cost' => 'float',
];
/**
* Validation rules
*/
public static $rules = [
'icao' => 'required',
'name' => 'required',
'lat' => 'required',
'lon' => 'required',
];
/**
* Some fancy callbacks
*/
protected static function boot()
{
parent::boot();
/**
* Make sure the ID is set to the ICAO
*/
static::creating(function (Airport $model) {
if(!empty($model->iata)) {
$model->iata = strtoupper($model->iata);
}
$model->icao = strtoupper($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;
}
}