grupa laravel przez subkery
return DB::table('candidates AS c')
->select( DB::raw('c.name AS c_name,j.name AS j_name,t.questions AS questions, count(g.grade) as countGrade'))
->join('job_openings AS j', 'c.fk_id_job_opening', '=','j.id_job_opening')
->join('interview_templates AS t', 'j.fk_id_template', '=', 't.id_template')
->join('responses AS r', 'r.fk_id_candidate', '=', 'c.id_candidate')
->join('grades AS g', 'r.id_response', '=', 'g.fk_id_response')
->where('g.fk_id_user',Auth::id())
->groupBy('c_name', 'j_name', 'questions')
->get();
Smoggy Skipper