2017-12-26 05:19:34 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
|
2020-03-23 21:31:35 +08:00
|
|
|
use App\Contracts\Resource;
|
2019-07-23 20:41:20 +08:00
|
|
|
use App\Support\Units\Distance;
|
|
|
|
use App\Support\Units\Fuel;
|
|
|
|
|
2020-04-01 05:26:55 +08:00
|
|
|
/**
|
|
|
|
* @mixin \App\Models\Acars
|
|
|
|
*/
|
2020-03-23 21:31:35 +08:00
|
|
|
class Acars extends Resource
|
2017-12-26 05:19:34 +08:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Transform the resource into an array.
|
|
|
|
*
|
2018-08-27 00:40:04 +08:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
*
|
2019-07-23 20:41:20 +08:00
|
|
|
* @throws \PhpUnitsOfMeasure\Exception\NonNumericValue
|
|
|
|
* @throws \PhpUnitsOfMeasure\Exception\NonStringUnitName
|
|
|
|
*
|
2017-12-26 05:19:34 +08:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function toArray($request)
|
|
|
|
{
|
2019-07-16 03:14:40 +08:00
|
|
|
$res = parent::toArray($request);
|
2018-05-04 04:07:16 +08:00
|
|
|
|
2019-07-23 20:41:20 +08:00
|
|
|
// Set these to the response units
|
2019-11-19 23:06:07 +08:00
|
|
|
$distance = !empty($res['distance']) ? $res['distance'] : 0;
|
|
|
|
$distance = new Distance($distance, config('phpvms.internal_units.distance'));
|
|
|
|
$res['distance'] = $distance->getResponseUnits();
|
2019-07-23 20:41:20 +08:00
|
|
|
|
2019-11-19 23:06:07 +08:00
|
|
|
$fuel = !empty($res['fuel']) ? $res['fuel'] : 0;
|
|
|
|
$fuel = new Fuel($fuel, config('phpvms.internal_units.fuel'));
|
|
|
|
$res['fuel'] = $fuel->getResponseUnits();
|
2018-05-04 04:07:16 +08:00
|
|
|
|
2020-04-01 05:26:55 +08:00
|
|
|
$res['pirep'] = Pirep::make($this->whenLoaded('pirep'));
|
|
|
|
|
2019-07-16 03:14:40 +08:00
|
|
|
return $res;
|
2017-12-26 05:19:34 +08:00
|
|
|
}
|
|
|
|
}
|