I am tying to retrieve data from my data base using leftJoin in laravel. I have two table name users and appointments in my appointments table there is a field name doctor_id that holds the doctor id related to the id in users. both the id value is same. I need the name of doctors from users table and appointment_date , status from appointments table if the column id value in users table matches column appointments value in appointments table with a where clause where patient_id = $patientID. But when I execute my query it returns empty response.
code
$patientID = $request->patientID;
$prevAppointments = DB::table('appointments')
->leftJoin('users', 'appointments.doctor_id', '=', 'users.id')
->select(
'users.first_name',
'users.last_name',
'appointments.appointment_date',
'appointments.status'
)
->where('appointments.patient_id', $patientID)
->get();
return($prevAppointments);
user table

appointments table
