phpvms/app/Models/Subfleet.php

111 lines
2.7 KiB
PHP
Raw Normal View History

<?php
namespace App\Models;
use App\Contracts\Model;
use App\Models\Enums\AircraftStatus;
use App\Models\Traits\ExpensableTrait;
use App\Models\Traits\FilesTrait;
/**
2018-04-23 21:46:28 +08:00
* @property int id
* @property string type
* @property string simbrief_type
2018-04-23 21:46:28 +08:00
* @property string name
* @property int airline_id
* @property int hub_id
2018-04-23 21:46:28 +08:00
* @property string ground_handling_multiplier
* @property Fare[] fares
* @property float cost_block_hour
* @property float cost_delay_minute
* @property Airline airline
* @property Airport hub
* @property int fuel_type
*/
class Subfleet extends Model
{
use ExpensableTrait;
use FilesTrait;
2018-03-21 08:40:19 +08:00
public $fillable = [
'airline_id',
'hub_id',
2017-07-05 22:55:36 +08:00
'type',
'simbrief_type',
'name',
2017-07-05 22:55:36 +08:00
'fuel_type',
'cost_block_hour',
'cost_delay_minute',
'ground_handling_multiplier',
'cargo_capacity',
'fuel_capacity',
'gross_weight',
];
public $table = 'subfleets';
2018-03-21 08:40:19 +08:00
public $casts = [
'airline_id' => 'integer',
'turn_time' => 'integer',
'cost_block_hour' => 'float',
'cost_delay_minute' => 'float',
'fuel_type' => 'integer',
'ground_handling_multiplier' => 'float',
'cargo_capacity' => 'float',
'fuel_capacity' => 'float',
'gross_weight' => 'float',
];
2018-03-21 08:40:19 +08:00
public static $rules = [
2018-03-22 01:35:06 +08:00
'type' => 'required',
'name' => 'required',
'hub_id' => 'nullable',
'ground_handling_multiplier' => 'nullable|numeric',
2017-12-31 04:37:10 +08:00
];
/**
* @param $type
*/
public function setTypeAttribute($type)
{
2018-08-27 00:40:04 +08:00
$type = str_replace([' ', ','], ['-', ''], $type);
$this->attributes['type'] = $type;
}
/**
* Relationships
*/
public function aircraft()
{
return $this->hasMany(Aircraft::class, 'subfleet_id')
->where('status', AircraftStatus::ACTIVE);
}
public function airline()
{
return $this->belongsTo(Airline::class, 'airline_id');
}
public function hub()
{
return $this->hasOne(Airport::class, 'id', 'hub_id');
}
2017-06-25 00:09:27 +08:00
public function fares()
{
2018-01-08 23:22:12 +08:00
return $this->belongsToMany(Fare::class, 'subfleet_fare')
->withPivot('price', 'cost', 'capacity');
2017-06-25 00:09:27 +08:00
}
public function flights()
{
2018-03-21 05:11:24 +08:00
return $this->belongsToMany(Flight::class, 'flight_subfleet');
}
public function ranks()
{
2018-01-08 23:22:12 +08:00
return $this->belongsToMany(Rank::class, 'subfleet_rank')
->withPivot('acars_pay', 'manual_pay');
}
}