minaremonshaker's avatar

Differentiating One-to-One and One-to-Many Morph Relationships for User Uploads in Laravel

Suppose I have a single table and model for uploading all application files related to a users or any other model (like:posts etc...), including their profile picture and other documents. The profile picture uses a morphOne (one-to-one polymorphic) relationship, while the other documents use a morphMany (one-to-many polymorphic) relationship. In Laravel, how can I distinguish between these two relationships when retrieving data from the uploads table?

0 likes
2 replies
Tray2's avatar
Tray2
Best Answer
Level 73

I would suggest keeping it separate, the profile pic belongs to the profile as just an avatar_name, while the uploaded documents is a classing many to many relation. I would not mix these two into the same table, since they are quite different entities.

Please or to participate in this conversation.