phpvms/app/Models/Transformers/FlightTransformer.php

39 lines
974 B
PHP
Raw Normal View History

2017-08-15 07:26:20 +08:00
<?php
namespace App\Models\Transformers;
use App\Models\Flight;
2017-08-15 12:36:49 +08:00
use League\Fractal\TransformerAbstract;
2017-08-15 07:26:20 +08:00
class FlightTransformer extends TransformerAbstract
{
2017-08-15 12:36:49 +08:00
public static $aptXform = null;
public function __construct()
{
FlightTransformer::$aptXform = new AirportTransform();
}
2017-08-15 07:26:20 +08:00
public function transform(Flight $flight)
{
$ret = [
'id' => $flight->id,
'airline' => [
'id' => $flight->airline->id,
'code' => $flight->airline->code,
'name' => $flight->airline->name,
],
2017-08-15 12:36:49 +08:00
'dpt' => FlightTransformer::$aptXform->transform($flight->dpt_airport),
'arr' => FlightTransformer::$aptXform->transform($flight->arr_airport),
2017-08-15 07:26:20 +08:00
'alt' => [],
];
if($flight->alt_airport_id) {
2017-08-15 12:36:49 +08:00
$flight['alt'] = FlightTransformer::$aptXform->transform($flight->alt_airport);
2017-08-15 07:26:20 +08:00
}
return $ret;
}
}