where('doctor_id', $doctorId) ->where('booking_date', $date) ->where('booking_time', $time) ->where('status', 'assigned') ->countAllResults() > 0; } public function syncBooking(int $appointmentId, int $doctorId, string $date, string $time, string $status, ?int $createdBy = null) { $existing = $this->where('appointment_id', $appointmentId)->first(); $data = [ 'appointment_id' => $appointmentId, 'doctor_id' => $doctorId, 'booking_date' => $date, 'booking_time' => $time, 'status' => $status, 'created_by' => $createdBy ]; if ($existing) { return $this->update($existing['id'], $data); } return $this->insert($data); } }