2017-12-26 05:19:34 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
|
2019-07-23 20:41:20 +08:00
|
|
|
use App\Support\Units\Distance;
|
|
|
|
use App\Support\Units\Fuel;
|
|
|
|
|
2019-07-16 03:14:40 +08:00
|
|
|
class Acars extends Response
|
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
|
|
|
|
if (!empty($res['distance'])) {
|
|
|
|
$distance = new Distance($res['distance'], config('phpvms.internal_units.distance'));
|
|
|
|
$res['distance'] = $distance->getResponseUnits();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($res['fuel'])) {
|
|
|
|
$fuel = new Fuel($res['fuel'], config('phpvms.internal_units.fuel'));
|
|
|
|
$res['fuel'] = $fuel->getResponseUnits();
|
|
|
|
}
|
2018-05-04 04:07:16 +08:00
|
|
|
|
2019-07-16 03:14:40 +08:00
|
|
|
return $res;
|
2017-12-26 05:19:34 +08:00
|
|
|
}
|
|
|
|
}
|