I have a one to one relationship between Registration and Evaluation. A registration can have an evaluation. A registration has student_id, course_no, course_name, instructor_name and I want to get all distinct courses with the evaluation count.
Ex.
| id | student_id | course_no | course_name | instructor_name |
| -- | --------- | ---------- | ------------ | --------------- |
| 1 | 1 |CSC 123 A | Intro | John Doe |
| 2 | 1 | CSC 098 C | Data | Kate Paul |
| 3 | 2 | CSC 123 A | Intro | John Doe |
And each of these has an evaluation. So I want the end result to look like:
| course_no | course_name | instructor_name | evaluation_count |
| ---------- | ------------ | --------------- | ---------------- |
| CSC 123 A | Intro. | John Doe | 2 |
| CSC 098 C | Data | Kate Paul | 1 |
So far I have the below code:
Registration::select('id', 'course_no', 'course_name', 'instructor_name', 'semester', 'section_type')
->withCount('evaluation')->get();
With this I get repeated courses.
P.S. I tried group by too and it does the same.