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
|
|
|
|
{
|
|
|
|
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-02-11 11:16:32 +08:00
|
|
|
// Return multiple measures so the client can pick what they want
|
2018-02-11 12:04:30 +08:00
|
|
|
if(\in_array('distance', $flight, true)
|
|
|
|
&& $flight['distance'] instanceof Distance)
|
|
|
|
{
|
|
|
|
$flight['distance'] = $flight['distance']->toObject();
|
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-02-05 02:39:51 +08:00
|
|
|
|
|
|
|
return $flight;
|
2017-12-12 21:25:11 +08:00
|
|
|
}
|
|
|
|
}
|