Hello Laravel community,
I’m currently working on a Laravel application where I have the following models and relationships:
Classe: A Classe has many Subjects.
Subject: Each Subject has many Exams through a pivot table exam_subject.
Exam: An Exam can have multiple Subjects.
I want to define a relationship in Laravel that allows me to fetch all Classes associated with a given Exam through the Subject model.
I defined a hasManyThrough relationship, but it doesn’t seem to fit this many-to-many scenario with the pivot table involved.
Could someone help me set up the proper relationship or query to achieve this?
Thank you in advance for your help!
user is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1