2017-06-23 09:55:45 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\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;
|
2019-08-27 02:43:50 +08:00
|
|
|
use App\Models\Traits\FilesTrait;
|
2018-02-24 06:37:10 +08:00
|
|
|
|
2017-06-23 09:55:45 +08:00
|
|
|
/**
|
|
|
|
* Class Subfleet
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-04-23 21:46:28 +08:00
|
|
|
* @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
|
2019-11-19 23:06:07 +08:00
|
|
|
* @property int airline_id
|
2017-06-23 09:55:45 +08:00
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
class Subfleet extends Model
|
2017-06-23 09:55:45 +08:00
|
|
|
{
|
2018-03-08 22:51:36 +08:00
|
|
|
use ExpensableTrait;
|
2019-08-27 02:43:50 +08:00
|
|
|
use FilesTrait;
|
2018-03-06 11:24:49 +08:00
|
|
|
|
2017-06-23 09:55:45 +08:00
|
|
|
public $table = 'subfleets';
|
|
|
|
|
2018-03-21 08:40:19 +08:00
|
|
|
public $fillable = [
|
2017-06-23 09:55:45 +08:00
|
|
|
'airline_id',
|
2017-07-05 22:55:36 +08:00
|
|
|
'type',
|
2018-03-21 08:17:11 +08:00
|
|
|
'name',
|
2018-03-30 02:42:16 +08:00
|
|
|
'turn_time',
|
2017-07-05 22:55:36 +08:00
|
|
|
'fuel_type',
|
2018-02-24 06:00:14 +08:00
|
|
|
'ground_handling_multiplier',
|
2018-01-04 12:04:51 +08:00
|
|
|
'cargo_capacity',
|
|
|
|
'fuel_capacity',
|
|
|
|
'gross_weight',
|
2017-06-23 09:55:45 +08:00
|
|
|
];
|
|
|
|
|
2018-03-21 08:40:19 +08:00
|
|
|
public $casts = [
|
2018-03-20 09:50:40 +08:00
|
|
|
'airline_id' => 'integer',
|
2018-03-30 02:42:16 +08:00
|
|
|
'turn_time' => 'integer',
|
|
|
|
'cost_block_hour' => 'float',
|
|
|
|
'cost_delay_minute' => 'float',
|
2018-03-20 09:50:40 +08:00
|
|
|
'fuel_type' => 'integer',
|
|
|
|
'ground_handling_multiplier' => 'float',
|
|
|
|
'cargo_capacity' => 'float',
|
|
|
|
'fuel_capacity' => 'float',
|
|
|
|
'gross_weight' => 'float',
|
2017-06-23 09:55:45 +08:00
|
|
|
];
|
|
|
|
|
2018-03-21 08:40:19 +08:00
|
|
|
public static $rules = [
|
2018-03-22 01:35:06 +08:00
|
|
|
'type' => 'required',
|
2018-03-20 09:50:40 +08:00
|
|
|
'name' => 'required',
|
|
|
|
'ground_handling_multiplier' => 'nullable|numeric',
|
2017-12-31 04:37:10 +08:00
|
|
|
];
|
|
|
|
|
2018-02-22 10:16:49 +08:00
|
|
|
/**
|
2018-03-20 09:50:40 +08:00
|
|
|
* @param $type
|
2018-02-22 10:16:49 +08:00
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
public function setTypeAttribute($type)
|
2018-02-22 10:16:49 +08:00
|
|
|
{
|
2018-08-27 00:40:04 +08:00
|
|
|
$type = str_replace([' ', ','], ['-', ''], $type);
|
2018-03-20 09:50:40 +08:00
|
|
|
$this->attributes['type'] = $type;
|
2018-02-22 10:16:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Relationships
|
|
|
|
*/
|
2017-12-13 06:58:27 +08:00
|
|
|
public function aircraft()
|
|
|
|
{
|
2018-02-24 06:37:10 +08:00
|
|
|
return $this->hasMany(Aircraft::class, 'subfleet_id')
|
2018-03-20 09:50:40 +08:00
|
|
|
->where('status', AircraftStatus::ACTIVE);
|
2017-12-13 06:58:27 +08:00
|
|
|
}
|
|
|
|
|
2017-06-23 09:55:45 +08:00
|
|
|
public function airline()
|
|
|
|
{
|
2018-01-06 00:45:34 +08:00
|
|
|
return $this->belongsTo(Airline::class, 'airline_id');
|
2017-06-23 09:55:45 +08:00
|
|
|
}
|
|
|
|
|
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')
|
2018-03-20 09:50:40 +08:00
|
|
|
->withPivot('price', 'cost', 'capacity');
|
2017-06-25 00:09:27 +08:00
|
|
|
}
|
|
|
|
|
2017-06-24 06:33:18 +08:00
|
|
|
public function flights()
|
|
|
|
{
|
2018-03-21 05:11:24 +08:00
|
|
|
return $this->belongsToMany(Flight::class, 'flight_subfleet');
|
2017-06-24 06:33:18 +08:00
|
|
|
}
|
|
|
|
|
2017-06-23 09:55:45 +08:00
|
|
|
public function ranks()
|
|
|
|
{
|
2018-01-08 23:22:12 +08:00
|
|
|
return $this->belongsToMany(Rank::class, 'subfleet_rank')
|
2018-03-20 09:50:40 +08:00
|
|
|
->withPivot('acars_pay', 'manual_pay');
|
2017-06-23 09:55:45 +08:00
|
|
|
}
|
|
|
|
}
|