Level 75
Search for laravel calendar it might be helpful.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I'm working on a medical appointment scheduling system project.
What is the best way to get the first free time of a doctor and schedule it for the patient who just asked for an appointment?
database structure:
appointments table:
doctors_working_hours table:
Using eloquent, When a patient asks for an appointment with a doctor, I want to schedule the first next free time of the doctor according to the doctor's working hours.
Till now, I came to this:
class Appointment extends Model
{
/**
* Schedules an appointment.
*
* @param array $data including doctor_id and patient_id
* @return \App\Appointment
*/
public static function schedule($data)
{
$doctor = User::find($data['doctor_id']);
$lastAppointment = $doctor->appointments()
// ->select('end_time')
->latest('end_time')
->first();
$dayOfWeek = $lastAppointment['end_time']->format('w');
$time = $lastAppointment['end_time']->format('H:i');
$workSchedules = $doctor->workSchedules()
->orderBy('day_of_week')
->orderBy('start_time')
->get();
}
}
this is incomplete.
the default duration for each appointment is 15 minutes.
How can I do this?
Please or to participate in this conversation.