2017-12-13 01:49:35 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
|
2018-02-11 12:04:30 +08:00
|
|
|
use App\Support\Units\Distance;
|
2018-02-21 04:07:33 +08:00
|
|
|
use App\Support\Units\Fuel;
|
2017-12-13 01:49:35 +08:00
|
|
|
use Illuminate\Http\Resources\Json\Resource;
|
|
|
|
|
|
|
|
class Pirep extends Resource
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Transform the resource into an array.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function toArray($request)
|
|
|
|
{
|
2018-01-05 11:21:51 +08:00
|
|
|
$pirep = parent::toArray($request);
|
|
|
|
|
2018-02-11 12:49:08 +08:00
|
|
|
if ($this->distance instanceof Distance) {
|
2018-02-11 12:30:42 +08:00
|
|
|
$pirep['distance'] = $this->distance->toObject();
|
2018-02-11 12:04:30 +08:00
|
|
|
}
|
|
|
|
|
2018-02-21 04:07:33 +08:00
|
|
|
if ($this->fuel_used instanceof Fuel) {
|
|
|
|
$pirep['fuel_used'] = $this->fuel_used->toObject();
|
|
|
|
}
|
|
|
|
|
2018-02-11 12:49:08 +08:00
|
|
|
if ($this->planned_distance instanceof Distance) {
|
2018-02-11 12:30:42 +08:00
|
|
|
$pirep['planned_distance'] = $this->planned_distance->toObject();
|
2018-02-11 12:04:30 +08:00
|
|
|
}
|
|
|
|
|
2018-02-12 10:38:56 +08:00
|
|
|
/*
|
|
|
|
* Relationship fields
|
|
|
|
*/
|
|
|
|
|
2018-01-05 11:21:51 +08:00
|
|
|
$pirep['airline'] = new Airline($this->airline);
|
|
|
|
$pirep['dpt_airport'] = new Airport($this->dpt_airport);
|
|
|
|
$pirep['arr_airport'] = new Airport($this->arr_airport);
|
|
|
|
$pirep['position'] = new Acars($this->position);
|
2018-01-25 06:22:49 +08:00
|
|
|
$pirep['comments'] = PirepComment::collection($this->comments);
|
2018-01-29 01:12:13 +08:00
|
|
|
$pirep['user'] = [
|
|
|
|
'id' => $this->user->id,
|
|
|
|
'name' => $this->user->name,
|
|
|
|
'home_airport_id' => $this->user->home_airport_id,
|
|
|
|
'curr_airport_id' => $this->user->curr_airport_id,
|
|
|
|
];
|
2018-01-05 11:21:51 +08:00
|
|
|
|
2018-02-07 03:59:40 +08:00
|
|
|
$pirep['fields'] = $this->fields;
|
|
|
|
|
2018-01-05 11:21:51 +08:00
|
|
|
return $pirep;
|
2017-12-13 01:49:35 +08:00
|
|
|
}
|
|
|
|
}
|