2017-12-12 21:25:11 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
|
2019-07-23 20:41:20 +08:00
|
|
|
use App\Support\Units\Distance;
|
|
|
|
|
2019-07-16 03:14:40 +08:00
|
|
|
class Flight extends Response
|
2017-12-12 21:25:11 +08:00
|
|
|
{
|
2018-03-23 11:48:54 +08:00
|
|
|
/**
|
|
|
|
* Set the fields on the flight object
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-23 11:48:54 +08:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function setFields()
|
|
|
|
{
|
|
|
|
$fields = [];
|
|
|
|
foreach ($this->field_values as $field) {
|
|
|
|
$fields[$field->name] = $field->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
2019-07-23 20:41:20 +08:00
|
|
|
/**
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
*
|
|
|
|
* @throws \PhpUnitsOfMeasure\Exception\NonNumericValue
|
|
|
|
* @throws \PhpUnitsOfMeasure\Exception\NonStringUnitName
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2017-12-12 21:25:11 +08:00
|
|
|
public function toArray($request)
|
|
|
|
{
|
2019-07-16 03:14:40 +08:00
|
|
|
$res = parent::toArray($request);
|
2017-12-13 06:58:27 +08:00
|
|
|
|
2019-07-16 03:14:40 +08:00
|
|
|
$res['ident'] = $this->ident;
|
2018-05-14 05:59:35 +08:00
|
|
|
|
2019-07-23 20:41:20 +08:00
|
|
|
if (!empty($res['distance'])) {
|
|
|
|
$distance = new Distance($res['distance'], config('phpvms.internal_units.distance'));
|
|
|
|
$res['distance'] = $distance->getResponseUnits();
|
|
|
|
}
|
2018-02-11 11:16:32 +08:00
|
|
|
|
2019-07-16 03:14:40 +08:00
|
|
|
$res['airline'] = new Airline($this->airline);
|
|
|
|
$res['subfleets'] = Subfleet::collection($this->subfleets);
|
|
|
|
$res['fields'] = $this->setFields();
|
2018-02-05 02:39:51 +08:00
|
|
|
|
2019-07-16 03:14:40 +08:00
|
|
|
return $res;
|
2017-12-12 21:25:11 +08:00
|
|
|
}
|
|
|
|
}
|