/** * GET (HTTP), /missions/{slug}. Where slug is a slugged name of the Mission. * * @param $slug * @return \Illuminate\View\View */ public function get($slug) { $mission = Mission::with(['telemetry', 'orbitalElements' => function ($query) { $query->orderBy('epoch', 'desc')->take(5); }, 'payloads'])->whereSlug($slug)->first(); $data = ['mission' => $mission, 'pastMission' => Mission::before($mission->launch_order_id, 1)->first(['mission_id', 'slug', 'name']), 'futureMission' => Mission::after($mission->launch_order_id, 1)->first(['mission_id', 'slug', 'name']), 'images' => $mission->objects()->inMissionControl()->wherePublic()->where('type', MissionControlType::Image)->orderBy('created_at')->get()]; if ($mission->status === MissionStatus::Upcoming || $mission->status === MissionStatus::InProgress) { return $this->getFutureMission($data); } else { return $this->getPastMission($data); } }
public function getTurnaroundTimeAttribute() { if ($this->status == MissionStatus::Complete) { $previousMission = Mission::before()->first(); return Carbon::parse($previousMission->launch_date_time)->diffInSeconds(Carbon::parse($this->launch_date_time)); } return null; }