cac
10 months ago

Relationship convention for a particular case

Posted 10 months ago by cac

Usually I review laravel's official documentation for relationship conventions but this time I didn't see any that fits my scenario. Can anyone please help me?

I have a USERS table and a REFERRALS table in which a user can refer another user (one to many). So the REFERRALS table would be like this:

REFERRALS

  • id
  • user_id(referee)
  • user_id(referred)

What would be the convention or the most elegant way to implement this? Is there a way that I don't need to do any customization to the relationship? How would I write the relationship methods on the model in this case?

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