2017-06-29 08:54:05 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Eloquent as Model;
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Pirep
|
|
|
|
*
|
|
|
|
* @package App\Models
|
|
|
|
*/
|
|
|
|
class Pirep extends Model
|
|
|
|
{
|
|
|
|
use Uuids;
|
|
|
|
use SoftDeletes;
|
|
|
|
|
|
|
|
public $table = 'pireps';
|
2017-07-05 02:57:08 +08:00
|
|
|
public $incrementing = false;
|
2017-06-29 08:54:05 +08:00
|
|
|
|
|
|
|
protected $dates = ['deleted_at'];
|
|
|
|
|
|
|
|
public $fillable
|
|
|
|
= [
|
|
|
|
'user_id',
|
|
|
|
'flight_id',
|
|
|
|
'aircraft_id',
|
|
|
|
'flight_time',
|
|
|
|
'route_code',
|
|
|
|
'route_leg',
|
|
|
|
'dpt_airport_id',
|
|
|
|
'arr_airport_id',
|
2017-07-11 07:54:51 +08:00
|
|
|
'fuel_used',
|
2017-07-04 14:05:37 +08:00
|
|
|
'source',
|
2017-06-29 08:54:05 +08:00
|
|
|
'level',
|
|
|
|
'route',
|
|
|
|
'notes',
|
|
|
|
'status',
|
|
|
|
'raw_data',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that should be casted to native types.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $casts
|
|
|
|
= [
|
|
|
|
'flight_time' => 'integer',
|
|
|
|
'level' => 'integer',
|
2017-07-11 07:54:51 +08:00
|
|
|
'fuel_used' => 'integer',
|
2017-07-04 14:05:37 +08:00
|
|
|
'source' => 'integer',
|
|
|
|
'status' => 'integer',
|
2017-06-29 08:54:05 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validation rules
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public static $rules
|
|
|
|
= [
|
|
|
|
'dpt_airport_id' => 'required',
|
|
|
|
'arr_airport_id' => 'required',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Foreign Keys
|
|
|
|
*/
|
2017-07-03 10:25:48 +08:00
|
|
|
public function aircraft()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('App\Models\Aircraft', 'aircraft_id');
|
|
|
|
}
|
2017-06-29 08:54:05 +08:00
|
|
|
|
2017-07-23 22:45:33 +08:00
|
|
|
public function airline()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('App\Models\Airline', 'airline_id');
|
|
|
|
}
|
|
|
|
|
2017-06-30 04:50:16 +08:00
|
|
|
public function arr_airport()
|
2017-06-29 08:54:05 +08:00
|
|
|
{
|
2017-06-30 04:50:16 +08:00
|
|
|
return $this->belongsTo('App\Models\Airport', 'arr_airport_id');
|
2017-06-29 08:54:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-30 04:50:16 +08:00
|
|
|
public function dpt_airport()
|
2017-06-29 08:54:05 +08:00
|
|
|
{
|
2017-06-30 04:50:16 +08:00
|
|
|
return $this->belongsTo('App\Models\Airport', 'dpt_airport_id');
|
2017-06-29 08:54:05 +08:00
|
|
|
}
|
|
|
|
|
2017-07-24 02:07:41 +08:00
|
|
|
public function events()
|
|
|
|
{
|
|
|
|
return $this->hasMany('App\Models\PirepEvent', 'pirep_id');
|
|
|
|
}
|
|
|
|
|
2017-06-30 04:50:16 +08:00
|
|
|
public function fields()
|
2017-06-29 08:54:05 +08:00
|
|
|
{
|
2017-06-30 04:50:16 +08:00
|
|
|
return $this->hasMany('App\Models\PirepFieldValues', 'pirep_id');
|
2017-06-29 08:54:05 +08:00
|
|
|
}
|
|
|
|
|
2017-06-30 04:50:16 +08:00
|
|
|
public function flight()
|
2017-06-29 08:54:05 +08:00
|
|
|
{
|
2017-06-30 04:50:16 +08:00
|
|
|
return $this->belongsTo('App\Models\Flight', 'flight_id');
|
|
|
|
}
|
|
|
|
|
2017-07-04 14:05:37 +08:00
|
|
|
public function pilot()
|
|
|
|
{
|
|
|
|
return $this->user();
|
|
|
|
}
|
|
|
|
|
2017-06-30 04:50:16 +08:00
|
|
|
public function user()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('App\Models\User', 'user_id');
|
2017-06-29 08:54:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|