Please what will be the right way to write this query using active-record

Hello guys,

Trust you all good. Please i need your help, i am trying to do a query using active-record

QuizSummaryDetails

id, quiz_id, homework_id, student_id, question_id, selected,answer,topic_id,created_at

Homework

id,teacher_id,subject_id,class_id,school_id,exam_type_id,slug,title,description,topic_id,curriculum_id,publish_status

,access_status,open_date,close_date,duration,status,created_at

I want to find the best performing topic

below is the code i wrote that doesnt work

->select(‘quiz_summary_details.*’)

->innerJoin(‘homeworks’, ‘quiz_summary_details.homework_id = homeworks.id’)

->where([‘homeworks.class_id’ =>$id])

->groupBy(‘topic_id’)

->sum(’quiz_summary_details.topic_id’);

->all();

Please whats the right way to achieve this?