82 lines
1.6 KiB
PHP
82 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\Enums\AircraftStatus;
|
|
use App\Support\ICAO;
|
|
|
|
class Aircraft extends BaseModel
|
|
{
|
|
public $table = 'aircraft';
|
|
|
|
public $fillable = [
|
|
'subfleet_id',
|
|
'airport_id',
|
|
'name',
|
|
'icao',
|
|
'registration',
|
|
'hex_code',
|
|
'zfw',
|
|
'status',
|
|
'state',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be casted to native types.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
'subfleet_id' => 'integer',
|
|
'zfw' => 'float',
|
|
'status' => 'integer',
|
|
'state' => 'integer',
|
|
];
|
|
|
|
/**
|
|
* Validation rules
|
|
*
|
|
* @var array
|
|
*/
|
|
public static $rules = [
|
|
'subfleet_id' => 'required',
|
|
'name' => 'required',
|
|
];
|
|
|
|
/**
|
|
* Callbacks
|
|
*/
|
|
protected static function boot()
|
|
{
|
|
parent::boot();
|
|
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
|
|
*/
|
|
|
|
public function airport()
|
|
{
|
|
return $this->belongsTo(Airport::class, 'airport_id');
|
|
}
|
|
|
|
public function subfleet()
|
|
{
|
|
return $this->belongsTo(Subfleet::class, 'subfleet_id');
|
|
}
|
|
}
|