phpvms/app/Http/Resources/SimBrief.php
Nabeel S 1287766a46
Fix aircraft retrieval for Simbrief (#1089)
* Fix full aircraft retrieval for simbriefs

* F off StyleCI
2021-03-19 18:25:19 -04:00

40 lines
924 B
PHP

<?php
namespace App\Http\Resources;
use App\Contracts\Resource;
/**
* @mixin \App\Models\SimBrief
*/
class SimBrief extends Resource
{
public function toArray($request)
{
$data = [
'id' => $this->id,
'aircraft_id' => $this->aircraft_id,
'url' => url(route('api.flights.briefing', ['id' => $this->id])),
];
$fares = [];
try {
if (!empty($this->fare_data)) {
$fare_data = json_decode($this->fare_data, true);
foreach ($fare_data as $fare) {
$fares[] = new \App\Models\Fare($fare);
}
$fares = collect($fares);
}
} catch (\Exception $e) {
// Invalid fare data
}
$data['subfleet'] = new BidSubfleet($this->aircraft->subfleet, $this->aircraft, $fares);
return $data;
}
}