2017-12-12 21:25:11 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
|
2018-02-11 11:16:32 +08:00
|
|
|
use App\Support\Units\Distance;
|
2017-12-12 21:25:11 +08:00
|
|
|
use Illuminate\Http\Resources\Json\Resource;
|
|
|
|
|
|
|
|
class Flight extends Resource
|
|
|
|
{
|
2018-03-23 11:48:54 +08:00
|
|
|
/**
|
|
|
|
* Set the fields on the flight object
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function setFields()
|
|
|
|
{
|
|
|
|
$fields = [];
|
|
|
|
foreach ($this->field_values as $field) {
|
|
|
|
$fields[$field->name] = $field->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
2017-12-12 21:25:11 +08:00
|
|
|
public function toArray($request)
|
|
|
|
{
|
2018-02-05 02:39:51 +08:00
|
|
|
$flight = parent::toArray($request);
|
2017-12-13 06:58:27 +08:00
|
|
|
|
2018-05-14 05:59:35 +08:00
|
|
|
$flight['ident'] = $this->ident;
|
|
|
|
|
2018-02-11 11:16:32 +08:00
|
|
|
// Return multiple measures so the client can pick what they want
|
2018-03-20 09:50:40 +08:00
|
|
|
if ($this->distance instanceof Distance) {
|
2018-04-08 09:52:12 +08:00
|
|
|
$flight['distance'] = $this->distance->units;
|
2018-02-11 11:16:32 +08:00
|
|
|
}
|
|
|
|
|
2018-02-05 02:39:51 +08:00
|
|
|
$flight['airline'] = new Airline($this->airline);
|
2018-02-10 04:26:14 +08:00
|
|
|
$flight['subfleets'] = Subfleet::collection($this->subfleets);
|
2018-03-23 11:48:54 +08:00
|
|
|
$flight['fields'] = $this->setFields();
|
2018-02-05 02:39:51 +08:00
|
|
|
|
|
|
|
return $flight;
|
2017-12-12 21:25:11 +08:00
|
|
|
}
|
|
|
|
}
|