2017-06-23 09:55:45 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Subfleet
|
|
|
|
* @package App\Models
|
|
|
|
*/
|
2017-12-26 05:19:34 +08:00
|
|
|
class Subfleet extends BaseModel
|
2017-06-23 09:55:45 +08:00
|
|
|
{
|
|
|
|
public $table = 'subfleets';
|
|
|
|
|
|
|
|
public $fillable = [
|
|
|
|
'airline_id',
|
|
|
|
'name',
|
2017-07-05 22:55:36 +08:00
|
|
|
'type',
|
|
|
|
'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
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that should be casted to native types.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $casts = [
|
2018-02-24 06:00:14 +08:00
|
|
|
'airline_id' => 'integer',
|
|
|
|
'fuel_type' => 'integer',
|
|
|
|
'ground_handling_multiplier' => 'float',
|
|
|
|
'cargo_capacity' => 'float',
|
|
|
|
'fuel_capacity' => 'float',
|
|
|
|
'gross_weight' => 'float',
|
2017-06-23 09:55:45 +08:00
|
|
|
];
|
|
|
|
|
2017-12-31 04:37:10 +08:00
|
|
|
public static $rules = [
|
2018-02-24 06:00:14 +08:00
|
|
|
'name' => 'required',
|
|
|
|
'type' => 'required',
|
|
|
|
'ground_handling_multiplier' => 'nullable|numeric',
|
2017-12-31 04:37:10 +08:00
|
|
|
];
|
|
|
|
|
2018-02-22 10:16:49 +08:00
|
|
|
/**
|
|
|
|
* Modify some fields on the fly. Make sure the subfleet
|
|
|
|
* names don't have spaces in them.
|
|
|
|
*/
|
|
|
|
public static function boot()
|
|
|
|
{
|
|
|
|
parent::boot();
|
|
|
|
|
|
|
|
static::creating(function ($model) {
|
2018-02-22 10:18:50 +08:00
|
|
|
if (filled($model->type)) {
|
|
|
|
$model->type = str_replace(' ', '_', $model->type);
|
2018-02-22 10:16:49 +08:00
|
|
|
}
|
2018-02-24 06:00:14 +08:00
|
|
|
|
|
|
|
if(!filled($model->ground_handling_multiplier)) {
|
|
|
|
$model->ground_handling_multiplier = 100;
|
|
|
|
}
|
2018-02-22 10:16:49 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
static::updating(function ($model) {
|
2018-02-22 10:18:50 +08:00
|
|
|
if (filled($model->type)) {
|
|
|
|
$model->type = str_replace(' ', '_', $model->type);
|
2018-02-22 10:16:49 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Relationships
|
|
|
|
*/
|
|
|
|
|
2017-12-13 06:58:27 +08:00
|
|
|
public function aircraft()
|
|
|
|
{
|
2018-01-06 00:45:34 +08:00
|
|
|
return $this->hasMany(Aircraft::class, 'subfleet_id');
|
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')
|
|
|
|
->withPivot('price', 'cost', 'capacity');
|
2017-06-25 00:09:27 +08:00
|
|
|
}
|
|
|
|
|
2017-06-24 06:33:18 +08:00
|
|
|
public function flights()
|
|
|
|
{
|
2018-01-06 00:45:34 +08:00
|
|
|
return $this->belongsToMany(Flight::class, 'subfleet_flight');
|
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')
|
|
|
|
->withPivot('acars_pay', 'manual_pay');
|
2017-06-23 09:55:45 +08:00
|
|
|
}
|
|
|
|
}
|