2017-06-09 09:37:51 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
use App\Interfaces\Model;
|
2018-02-24 06:37:10 +08:00
|
|
|
use App\Models\Enums\AircraftStatus;
|
2018-03-08 22:51:36 +08:00
|
|
|
use App\Models\Traits\ExpensableTrait;
|
2018-02-13 10:58:23 +08:00
|
|
|
|
2018-03-03 07:29:11 +08:00
|
|
|
/**
|
2018-03-20 09:50:40 +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
|
2018-03-20 09:50:40 +08:00
|
|
|
* @property int status
|
|
|
|
* @property int state
|
|
|
|
* @package App\Models
|
2018-03-03 07:29:11 +08:00
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
class Aircraft extends Model
|
2017-06-09 09:37:51 +08:00
|
|
|
{
|
2018-03-08 22:51:36 +08:00
|
|
|
use ExpensableTrait;
|
2018-03-07 07:32:56 +08:00
|
|
|
|
2017-06-09 09:37:51 +08:00
|
|
|
public $table = 'aircraft';
|
2017-06-11 07:27:19 +08:00
|
|
|
|
2017-12-13 06:58:27 +08:00
|
|
|
public $fillable = [
|
|
|
|
'subfleet_id',
|
|
|
|
'airport_id',
|
|
|
|
'name',
|
2018-01-03 11:00:46 +08:00
|
|
|
'icao',
|
2017-12-13 06:58:27 +08:00
|
|
|
'registration',
|
2018-02-13 10:58:23 +08:00
|
|
|
'hex_code',
|
2018-01-31 00:04:50 +08:00
|
|
|
'zfw',
|
2018-02-24 06:37:10 +08:00
|
|
|
'status',
|
|
|
|
'state',
|
2017-12-13 06:58:27 +08:00
|
|
|
];
|
2017-06-09 09:37:51 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that should be casted to native types.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-12-13 06:58:27 +08:00
|
|
|
protected $casts = [
|
2018-03-20 09:50:40 +08:00
|
|
|
'subfleet_id' => 'integer',
|
|
|
|
'zfw' => 'float',
|
|
|
|
'status' => 'integer',
|
|
|
|
'state' => 'integer',
|
2017-12-13 06:58:27 +08:00
|
|
|
];
|
2017-06-09 09:37:51 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Validation rules
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-12-13 06:58:27 +08:00
|
|
|
public static $rules = [
|
2018-01-10 03:34:19 +08:00
|
|
|
'subfleet_id' => 'required',
|
2018-03-20 09:50:40 +08:00
|
|
|
'name' => 'required',
|
2017-12-13 06:58:27 +08:00
|
|
|
];
|
2017-06-10 11:19:17 +08:00
|
|
|
|
2018-01-04 12:04:51 +08:00
|
|
|
/**
|
2018-03-19 09:37:35 +08:00
|
|
|
* See if this aircraft is active
|
|
|
|
* @return bool
|
2018-01-04 12:04:51 +08:00
|
|
|
*/
|
2018-03-19 09:37:35 +08:00
|
|
|
public function getActiveAttribute(): bool
|
2018-01-04 12:04:51 +08:00
|
|
|
{
|
2018-03-19 09:37:35 +08:00
|
|
|
return $this->status === AircraftStatus::ACTIVE;
|
2018-01-04 12:04:51 +08:00
|
|
|
}
|
|
|
|
|
2018-03-19 09:37:35 +08:00
|
|
|
/**
|
|
|
|
* Capitalize the ICAO when set
|
|
|
|
* @param $icao
|
|
|
|
*/
|
|
|
|
public function setIcaoAttribute($icao): void
|
2018-02-24 06:37:10 +08:00
|
|
|
{
|
2018-03-19 09:37:35 +08:00
|
|
|
$this->attributes['icao'] = strtoupper($icao);
|
2018-02-24 06:37:10 +08:00
|
|
|
}
|
|
|
|
|
2017-06-10 11:19:17 +08:00
|
|
|
/**
|
2017-06-23 09:55:45 +08:00
|
|
|
* foreign keys
|
2017-06-10 11:19:17 +08:00
|
|
|
*/
|
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
|
|
|
|
2017-06-23 09:55:45 +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
|
|
|
}
|