For a referral program I have two tables. users
(with an id
and some other columns) and referrals
(with a referrer_id
and a referred_id
).
A User
may have many referred users, and User
may have only one referrer User
. So User
model should be like:
class User extends Model
{
public function referrerUser()
{
// There may be only one referrer user for this user
}
public function referredUsers()
{
// There may be many referred users for this user
}
}
I read some messages about this, but I'm a bit confused about the right way to do this. So, how can I return these relations using belongsTo
(for referrerUser
method) and belongsToMany
(for referredUsers
method)?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire