好吧,我认为您可以从以下内容开始:
class Users extends Eloquent {
protected $table = 'users';
public function profile()
{
return $this->belongsTo('Profile');
}
public function followers()
{
return $this->hasMany('Follower', 'follower_id', 'id');
}
public function following()
{
return $this->hasMany('Follower', 'following_id', 'id');
}
}
class Hab extends Eloquent {
protected $table = 'habs';
public function user()
{
return $this->belongsTo('User');
}
}
class Follower extends Eloquent {
protected $table = 'followers';
}
class Profile extends Eloquent {
protected $table = 'profiles';
}
你应该能够:
正常选择用户
$user = User::find(1);
得到它的住所
$habs = $user->habs;
获得它的追随者
$followers = $user->followers;
获取关注他/她的人
$following = $user->following;
获得他们追随者的所有习惯
foreach($user->followers as $follower)
{
$followerEmail = $follower->email;
$followerName = $follower->profile->name;
$followerHabs = $follower->habs;
}
从他/她关注的人那里获取所有习惯
foreach($user->following as $following)
{
$followingEmail = $following->email;
$followingName = $following->profile->name;
$followingHabs = $following->habs;
}