@ynoth25 enrollment belongsTo student, teacher and course https://laravel.com/docs/8.x/eloquent-relationships#one-to-many-inverse
Student, teacher and course hasMany enrollments https://laravel.com/docs/8.x/eloquent-relationships#one-to-many
get the courses that the students took together with the teacher details.
Course::whereHas('enrollments', fn ($query) => $query->where(<you condition for enrollments>))
->with('enrollments.teacher')
->get()