嗯,我認爲你可以像這樣開始:
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;
}
是'Habs'表的帖子表? – SamV
@fruityp是的 – MrFoh