2017-06-18 06:25:36 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2017-12-13 02:43:58 +08:00
|
|
|
use App\Models\Traits\HashId;
|
2017-08-13 01:24:00 +08:00
|
|
|
|
2017-12-26 05:19:34 +08:00
|
|
|
class Flight extends BaseModel
|
2017-06-18 06:25:36 +08:00
|
|
|
{
|
2017-12-13 02:43:58 +08:00
|
|
|
use HashId;
|
2017-06-25 02:20:24 +08:00
|
|
|
|
2017-06-18 06:25:36 +08:00
|
|
|
public $table = 'flights';
|
2017-06-25 02:20:24 +08:00
|
|
|
public $incrementing = false;
|
2017-06-18 06:25:36 +08:00
|
|
|
|
2017-12-13 03:59:05 +08:00
|
|
|
public $fillable = [
|
2018-01-30 08:14:55 +08:00
|
|
|
'id',
|
2017-12-13 03:59:05 +08:00
|
|
|
'airline_id',
|
|
|
|
'flight_number',
|
|
|
|
'route_code',
|
|
|
|
'route_leg',
|
|
|
|
'dpt_airport_id',
|
|
|
|
'arr_airport_id',
|
|
|
|
'alt_airport_id',
|
|
|
|
'dpt_time',
|
|
|
|
'arr_time',
|
2018-01-04 11:40:05 +08:00
|
|
|
'level',
|
|
|
|
'distance',
|
2018-01-30 08:14:55 +08:00
|
|
|
'flight_type',
|
|
|
|
'route',
|
2017-12-13 03:59:05 +08:00
|
|
|
'notes',
|
|
|
|
'has_bid',
|
|
|
|
'active',
|
|
|
|
];
|
2017-06-18 06:25:36 +08:00
|
|
|
|
2017-12-13 03:59:05 +08:00
|
|
|
protected $casts = [
|
|
|
|
'flight_number' => 'integer',
|
2018-01-04 11:40:05 +08:00
|
|
|
'level' => 'integer',
|
|
|
|
'distance' => 'float',
|
2018-01-30 08:14:55 +08:00
|
|
|
'flight_type' => 'integer',
|
2017-12-13 03:59:05 +08:00
|
|
|
'has_bid' => 'boolean',
|
|
|
|
'active' => 'boolean',
|
|
|
|
];
|
2017-06-18 06:25:36 +08:00
|
|
|
|
2017-12-13 03:59:05 +08:00
|
|
|
public static $rules = [
|
2018-01-24 11:58:13 +08:00
|
|
|
'airline_id' => 'required|exists:airlines,id',
|
2017-12-13 03:59:05 +08:00
|
|
|
'flight_number' => 'required',
|
2018-01-24 11:58:13 +08:00
|
|
|
'route_code' => 'nullable',
|
|
|
|
'route_leg' => 'nullable',
|
2017-12-13 03:59:05 +08:00
|
|
|
'dpt_airport_id' => 'required',
|
|
|
|
'arr_airport_id' => 'required',
|
2018-01-24 11:58:13 +08:00
|
|
|
'level' => 'nullable',
|
2017-12-13 03:59:05 +08:00
|
|
|
];
|
2017-06-18 06:25:36 +08:00
|
|
|
|
2017-12-20 10:19:36 +08:00
|
|
|
/**
|
|
|
|
* Get the flight ident, e.,g JBU1900
|
|
|
|
*/
|
|
|
|
public function getIdentAttribute()
|
2017-12-13 06:58:27 +08:00
|
|
|
{
|
2017-12-21 09:12:39 +08:00
|
|
|
$flight_id = $this->airline->code;
|
|
|
|
$flight_id .= $this->flight_number;
|
2017-12-13 06:58:27 +08:00
|
|
|
|
2017-12-21 09:12:39 +08:00
|
|
|
# TODO: Add in code/leg if set
|
|
|
|
|
|
|
|
return $flight_id;
|
2017-12-13 06:58:27 +08:00
|
|
|
}
|
|
|
|
|
2017-07-11 08:06:06 +08:00
|
|
|
/**
|
|
|
|
* Relationship
|
|
|
|
*/
|
|
|
|
|
2017-06-20 00:50:25 +08:00
|
|
|
public function airline()
|
|
|
|
{
|
2018-01-08 23:22:12 +08:00
|
|
|
return $this->belongsTo(Airline::class, 'airline_id');
|
2017-06-20 00:50:25 +08:00
|
|
|
}
|
|
|
|
|
2017-06-18 06:25:36 +08:00
|
|
|
public function dpt_airport()
|
|
|
|
{
|
2018-01-08 23:22:12 +08:00
|
|
|
return $this->belongsTo(Airport::class, 'dpt_airport_id');
|
2017-06-18 06:25:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function arr_airport()
|
|
|
|
{
|
2018-01-08 23:22:12 +08:00
|
|
|
return $this->belongsTo(Airport::class, 'arr_airport_id');
|
2017-06-18 06:25:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function alt_airport()
|
|
|
|
{
|
2018-01-08 23:22:12 +08:00
|
|
|
return $this->belongsTo(Airport::class, 'alt_airport_id');
|
2017-06-18 06:25:36 +08:00
|
|
|
}
|
|
|
|
|
2018-01-07 23:19:46 +08:00
|
|
|
public function fares()
|
|
|
|
{
|
2018-01-08 23:22:12 +08:00
|
|
|
return $this->belongsToMany(Fare::class, 'flight_fare')
|
|
|
|
->withPivot('price', 'cost', 'capacity');
|
2018-01-07 23:19:46 +08:00
|
|
|
}
|
|
|
|
|
2017-07-11 08:06:06 +08:00
|
|
|
public function fields()
|
|
|
|
{
|
2018-01-08 23:22:12 +08:00
|
|
|
return $this->hasMany(FlightFields::class, 'flight_id');
|
2017-07-11 08:06:06 +08:00
|
|
|
}
|
|
|
|
|
2017-06-24 06:33:18 +08:00
|
|
|
public function subfleets()
|
2017-06-18 06:25:36 +08:00
|
|
|
{
|
2018-01-08 23:22:12 +08:00
|
|
|
return $this->belongsToMany(Subfleet::class, 'subfleet_flight');
|
2017-06-18 06:25:36 +08:00
|
|
|
}
|
|
|
|
}
|