phpvms/app/Models/Aircraft.php

82 lines
1.6 KiB
PHP
Raw Normal View History

2017-06-09 09:37:51 +08:00
<?php
namespace App\Models;
use App\Models\Enums\AircraftStatus;
use App\Support\ICAO;
class Aircraft extends BaseModel
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',
];
/**
* Callbacks
*/
protected static function boot()
{
parent::boot();
2018-01-04 12:28:17 +08:00
static::creating(function (Aircraft $model) {
if (!empty($model->icao)) {
$model->icao = strtoupper(trim($model->icao));
}
if(empty($model->hex_code)) {
$model->hex_code = ICAO::createHexCode();
}
});
}
public function getActiveAttribute()
{
return $this->status === AircraftStatus::ACTIVE;
}
/**
* 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
}