schedules()->where('status', '=', ApprovalStatus::APPROVED)->first(); return [ 'id' => $this->id, 'type' => $this->type, 'courier' => $this->courier, 'tracking_number' => $this->tracking_number, 'dispatch_date' => $this->dispatch_date ? $this->dispatch_date->format('d-m-Y') : $this->dispatch_date, 'drop_date' => $this->drop_date ? $this->drop_date->format('d-m-Y') : $this->drop_date, 'status' => $this->status, 'current_schedule' => new ScheduleResource($currentSchedule), 'schedule_history' => ScheduleResource::collection($this->schedules()->where('status', '=', ApprovalStatus::EXPIRED)->get()), 'dropped_days' => Carbon::now()->diffInDays($this->drop_date, false), 'schedule_complete' => $currentSchedule ? $currentSchedule->eta <= Carbon::now() : false ]; } }