Ad
Query In Laravel Returns Empty Response
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
Ad
Answer
Try this -
$patientID = $request->patientID;
$prevAppointments = DB::table('appointments')
->leftJoin('users', 'appointments.doctor_id', '=', 'users.id')
->select('users.first_name','users.last_name','appointments.patient_id', 'appointments.appointment_date','appointments.status')
->where('appointments.patient_id',$patientID)
->get();
return($prevAppointments);
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad