2020-03-23 21:31:35 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
|
2020-05-16 06:20:16 +08:00
|
|
|
use App\Contracts\Resource;
|
2020-03-23 21:31:35 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @mixin \App\Models\SimBrief
|
|
|
|
*/
|
|
|
|
class SimBrief extends Resource
|
|
|
|
{
|
|
|
|
public function toArray($request)
|
|
|
|
{
|
2021-03-03 01:29:04 +08:00
|
|
|
$data = [
|
2021-03-20 06:25:19 +08:00
|
|
|
'id' => $this->id,
|
|
|
|
'aircraft_id' => $this->aircraft_id,
|
|
|
|
'url' => url(route('api.flights.briefing', ['id' => $this->id])),
|
2020-03-23 21:31:35 +08:00
|
|
|
];
|
2021-03-03 01:29:04 +08:00
|
|
|
|
2021-03-20 06:25:19 +08:00
|
|
|
$fares = [];
|
|
|
|
|
2021-03-03 01:29:04 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-03-20 06:25:19 +08:00
|
|
|
$fares = collect($fares);
|
2021-03-03 01:29:04 +08:00
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
// Invalid fare data
|
|
|
|
}
|
|
|
|
|
2021-03-20 06:25:19 +08:00
|
|
|
$data['subfleet'] = new BidSubfleet($this->aircraft->subfleet, $this->aircraft, $fares);
|
2021-03-03 01:29:04 +08:00
|
|
|
|
|
|
|
return $data;
|
2020-03-23 21:31:35 +08:00
|
|
|
}
|
|
|
|
}
|