I have 2 models
- Patient model with
id
,name
,address
- Appointment model with
id
,patient_id
,appointment_date
,status
Patient
model has many Appointments
.
I want to list Patients where patient’s previous Appointment status='closed'
only. Beacause I dont want to add new appointment to a patient whose appointment status is open
How can I achieve this with eloquent ?
2
Answers
you can query the patients with the desired condition using Eloquent:
Hope this helps!
Use whereNotIn for excluding only the id’s that have status
open
and return all the patients:This eloquent query is same as in sql :