0

I have five tables in MySQL, School, Student, Session, Class now I want to generate a report on Enrollment table it does not count the male or female students who are enrolled in 2019-2020, below are the controller function code

$enro=Enrollement::groupBy('class_id','class_section','session_id')
    ->get();

here is the view blade code

 <td style="border: 1px solid black;">{{ $value->students()->get()->where('student_gender','Male')->count() }} </td>
<td style="border: 1px solid black;">{{ $value->students()->get()->where('student_gender','Female')->count()}} </td>

it gets only 1 for Male and 1 for Female where I have 2 enrollment of Male and 2 for Female. I don't know how to solve this problem any suggestion
It is a simple report, for example, I want to show in session 2019-2020, Class 7th, Section A, the N Number of Female and Male Students are enrolled.

ismail
  • 5
  • 5
  • Does Enrolment table have all the data you need already ? why you mentioned you have others table ? i am just suggesting when you need to pull data from two or more tables you need to do join. https://laravel.com/docs/7.x/queries#joins or better you define relationship and use that. https://laravel.com/docs/7.x/eloquent-relationships – Jitesh Dhamaniya Sep 03 '20 at 02:40
  • Does this answer your question? [Laravel Eloquent groupBy() AND also return count of each group](https://stackoverflow.com/questions/18533080/laravel-eloquent-groupby-and-also-return-count-of-each-group) – Kamlesh Paul Sep 03 '20 at 04:06
  • it has the data, CURD is working successfully and other reports also working and relationship is also OK – ismail Sep 03 '20 at 04:53

0 Answers0