@computanians there no many-to-many relationships for 3 tables out of the box.
You can make belongsToMany relationships between 2 tables and pass additional value of third column https://laravel.com/docs/8.x/eloquent-relationships#syncing-associations. This way you will not be able to use eager loading for all 3 tables
You can create separated model for pivot table (like ClassSubjectTeacher) and define all the relationships on this model. This way you can use eager loading for all relations
You can try to play with https://laravel.com/docs/8.x/eloquent-relationships#has-many-through