4 months ago

Best Practice: Extends vs. One-to-one relationship

Posted 4 months ago by Rretzko

Hi - I'm looking for guidance on Eloquent Best Practice for using/avoiding extending models.

Example: three models: Student, Teacher, Parent.

Each is a User and each has common properties: first/last name, address, email, phone.

I've placed these common properties into a Person model.

Address, Email and Phone are separate models and coded as one-to-many or many-to-many relationships.

First_name and Last_name are one-to-one relationships as are the User properties.

Question: Should User->Person->Student, User->Person->Teacher and User->Person->Parent be defined as one-to-one relationships using HasOne()/BelongsTo() methods or simply extended as in traditional OOP structure?

Thanks for your thoughts!

Please sign in or create an account to participate in this conversation.