phpvms/app/Http/Resources/SimBrief.php

40 lines
919 B
PHP
Raw Normal View History

<?php
namespace App\Http\Resources;
2020-05-16 06:20:16 +08:00
use App\Contracts\Resource;
/**
* @mixin \App\Models\SimBrief
*/
class SimBrief extends Resource
{
public function toArray($request)
{
$data = [
'id' => $this->id,
'url' => url(route('api.flights.briefing', ['id' => $this->id])),
];
try {
if (!empty($this->fare_data)) {
$fares = [];
$fare_data = json_decode($this->fare_data, true);
foreach ($fare_data as $fare) {
$fares[] = new \App\Models\Fare($fare);
}
$this->aircraft->subfleet->fares = collect($fares);
}
} catch (\Exception $e) {
// Invalid fare data
}
2021-03-20 04:59:39 +08:00
if ($this->aircraft->subfleet) {
$data['subfleet'] = new Subfleet($this->aircraft->subfleet);
}
return $data;
}
}