Convert flight transformer to the native Laravel resource object
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Transformers;
|
||||
|
||||
use App\Models\Airport;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
class AirportTransform extends TransformerAbstract
|
||||
{
|
||||
public function transform(Airport $ap)
|
||||
{
|
||||
return [
|
||||
'id' => $ap->id,
|
||||
'icao' => $ap->icao,
|
||||
'name' => $ap->name,
|
||||
'location' => $ap->location,
|
||||
'country' => $ap->country,
|
||||
'fuel_100ll_cost' => $ap->fuel_100ll_cost,
|
||||
'fuel_jeta_cost' => $ap->fuel_jeta_cost,
|
||||
'fuel_mogas_cost' => $ap->fuel_mogas_cost,
|
||||
'lat' => $ap->lat,
|
||||
'lon' => $ap->lon,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Transformers;
|
||||
|
||||
use App\Models\Flight;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
|
||||
class FlightTransformer extends TransformerAbstract
|
||||
{
|
||||
public static $aptXform = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
FlightTransformer::$aptXform = new AirportTransform();
|
||||
}
|
||||
|
||||
public function transform(Flight $flight)
|
||||
{
|
||||
$ret = [
|
||||
'id' => $flight->id,
|
||||
'airline' => [
|
||||
'id' => $flight->airline->id,
|
||||
'code' => $flight->airline->code,
|
||||
'name' => $flight->airline->name,
|
||||
],
|
||||
'dpt' => FlightTransformer::$aptXform->transform($flight->dpt_airport),
|
||||
'arr' => FlightTransformer::$aptXform->transform($flight->arr_airport),
|
||||
'alt' => [],
|
||||
];
|
||||
|
||||
if($flight->alt_airport_id) {
|
||||
$flight['alt'] = FlightTransformer::$aptXform->transform($flight->alt_airport);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user