I have an eloquent model User which is in 1:N relation with itself (a single user can refer multiple users, and a single user can be referred by a single user only).
/*
* Get the user's referrals
*/
public function referrals()
{
return $this->belongsToMany('App\User');
}
/*
* Get the referred user's parent referral
*/
public function parentReferral()
{
return $this->belongsTo('App\User');
}
Does Laravel provide a native method that will count all the belongsToMany relations?
(A simple way I can do this is just get the parent user's id and manually count all the appearances, but I wish to know if there's a method given by Laravel that I can use on the object)
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2k5cLL0
via IFTTT
Aucun commentaire:
Enregistrer un commentaire