phpvms/app/Http/Resources/Flight.php
2018-02-10 22:04:30 -06:00

27 lines
666 B
PHP

<?php
namespace App\Http\Resources;
use App\Support\Units\Distance;
use Illuminate\Http\Resources\Json\Resource;
class Flight extends Resource
{
public function toArray($request)
{
$flight = parent::toArray($request);
// Return multiple measures so the client can pick what they want
if(\in_array('distance', $flight, true)
&& $flight['distance'] instanceof Distance)
{
$flight['distance'] = $flight['distance']->toObject();
}
$flight['airline'] = new Airline($this->airline);
$flight['subfleets'] = Subfleet::collection($this->subfleets);
return $flight;
}
}