phpvms/app/Models/Aircraft.php

93 lines
1.8 KiB
PHP
Raw Normal View History

2017-06-09 09:37:51 +08:00
<?php
namespace App\Models;
use App\Interfaces\Model;
use App\Models\Enums\AircraftStatus;
use App\Models\Traits\ExpensableTrait;
2018-03-03 07:29:11 +08:00
/**
* @property mixed subfleet_id
* @property string name
* @property string icao
* @property string registration
* @property string hex_code
* @property Airport airport
2018-03-03 07:29:11 +08:00
* @property Subfleet subfleet
* @property int status
* @property int state
* @package App\Models
2018-03-03 07:29:11 +08:00
*/
class Aircraft extends Model
2017-06-09 09:37:51 +08:00
{
use ExpensableTrait;
2017-06-09 09:37:51 +08:00
public $table = 'aircraft';
public $fillable = [
'subfleet_id',
'airport_id',
'name',
'icao',
'registration',
'hex_code',
2018-01-31 00:04:50 +08:00
'zfw',
'status',
'state',
];
2017-06-09 09:37:51 +08:00
/**
* The attributes that should be casted to native types.
*
* @var array
*/
protected $casts = [
'subfleet_id' => 'integer',
'zfw' => 'float',
'status' => 'integer',
'state' => 'integer',
];
2017-06-09 09:37:51 +08:00
/**
* Validation rules
*
* @var array
*/
public static $rules = [
'subfleet_id' => 'required',
'name' => 'required',
];
/**
* See if this aircraft is active
* @return bool
*/
public function getActiveAttribute(): bool
{
return $this->status === AircraftStatus::ACTIVE;
}
/**
* Capitalize the ICAO when set
* @param $icao
*/
public function setIcaoAttribute($icao): void
{
$this->attributes['icao'] = strtoupper($icao);
}
/**
* foreign keys
*/
2017-06-29 08:56:10 +08:00
2017-06-25 03:00:56 +08:00
public function airport()
{
2018-01-08 23:22:12 +08:00
return $this->belongsTo(Airport::class, 'airport_id');
2017-06-25 03:00:56 +08:00
}
2017-06-10 14:50:00 +08:00
public function subfleet()
{
2018-01-08 23:22:12 +08:00
return $this->belongsTo(Subfleet::class, 'subfleet_id');
2017-06-10 14:50:00 +08:00
}
2017-06-09 09:37:51 +08:00
}