$transport->id, 'type' => $transport->type, 'courier' => $transport->courier, 'tracking_number' => $transport->tracking_number, 'dispatch_date' => $transport->dispatch_date ? $transport->dispatch_date->format('d-m-Y') : $transport->dispatch_date, 'drop_date' => $transport->drop_date ? $transport->drop_date->format('d-m-Y') : $transport->drop_date, 'status' => $transport->status, 'dropped_days' => Carbon::now()->diffInDays($transport->drop_date, false), 'schedule_complete' => $this->isScheduleComplete($transport) ]; } /** * Include Current Schedule * @param Transport $transport * @return Item */ public function includeCurrentSchedule(Transport $transport): Item { $currentSchedule = $transport->schedules()->where('status', '=', ApprovalStatus::APPROVED)->first(); return $this->item($currentSchedule, new ScheduleTransformer); } /** * include Schedule History * @param Transport $transport * @return Collection */ public function includeScheduleHistory(Transport $transport): Collection { $history = $transport->schedules()->where('status', '=', ApprovalStatus::EXPIRED)->get(); return $this->collection($history, new ScheduleTransformer); } public function isScheduleComplete(Transport $transport): bool { $currentSchedule = $transport->schedules()->where('status', '=', ApprovalStatus::APPROVED)->first(); return $currentSchedule && $currentSchedule->eta <= Carbon::now(); } }