Yeah, this is a perfect example of a polymorphic relationship.
However, I would personally not create different Teacher and Student models. In the end, they are all users. I would probably create a user's table and have a many-to-many relationship between a user and a role. So a user can be both a teacher and a student at the same time in theory.
If the user can only have one rule, then I would store the role simply on the user itself and have a many-to-many relationship between the user and the group.