phpvms/app/Models/Subfleet.php
Nabeel S 3ec64c989b
Fixes (#435)
* Add flight level field to PIREP field closes #401

* Default value for distance 0 closes #400

* Block airline deletion if assets exist #367

* Formatting

* Move some of the base exception classes

* Fix skin references to use settings table

* Set default for theme name if setting is wrong
2019-11-19 10:06:07 -05:00

100 lines
2.4 KiB
PHP

<?php
namespace App\Models;
use App\Contracts\Model;
use App\Models\Enums\AircraftStatus;
use App\Models\Traits\ExpensableTrait;
use App\Models\Traits\FilesTrait;
/**
* Class Subfleet
*
* @property int id
* @property string type
* @property string name
* @property string ground_handling_multiplier
* @property Fare[] fares
* @property float cost_block_hour
* @property float cost_delay_minute
* @property Airline airline
* @property int airline_id
*/
class Subfleet extends Model
{
use ExpensableTrait;
use FilesTrait;
public $table = 'subfleets';
public $fillable = [
'airline_id',
'type',
'name',
'turn_time',
'fuel_type',
'ground_handling_multiplier',
'cargo_capacity',
'fuel_capacity',
'gross_weight',
];
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',
];
public static $rules = [
'type' => 'required',
'name' => 'required',
'ground_handling_multiplier' => 'nullable|numeric',
];
/**
* @param $type
*/
public function setTypeAttribute($type)
{
$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 fares()
{
return $this->belongsToMany(Fare::class, 'subfleet_fare')
->withPivot('price', 'cost', 'capacity');
}
public function flights()
{
return $this->belongsToMany(Flight::class, 'flight_subfleet');
}
public function ranks()
{
return $this->belongsToMany(Rank::class, 'subfleet_rank')
->withPivot('acars_pay', 'manual_pay');
}
}