I have an Appointment model that has a relation to Employee and an Employee to a User. I am trying to query a list of appointments between specific dates ($weekStart and $weekEnd) and retrieve the appointments as well as the related Employees and Users.
So far this works, it returns all my Clients with all appointments and the assigned Employees/Users (Employees belong to User).
'clients' => Client::with('careType','appointments.employees.user')->get(),
However I wish to specify between dates on the appointments model. So I have this:
$data = [
'clients' => Client::with(['appointments' => function ($query) use ($weekStart, $weekEnd) {
$query->whereBetween('starts_at', [$weekStart, $weekEnd]);
}])->get(),
];
In the above what is the syntax to also retrieve the employees and user models when I have a sub query?