Well, I think you can start with something like this:
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';
}
And you should be able to:
Select a user normally
$user = User::find(1);
Get its Habs
$habs = $user->habs;
Get its followers
$followers = $user->followers;
Get who are following him/her
$following = $user->following;
Get all habs of their Followers
foreach($user->followers as $follower)
{
$followerEmail = $follower->email;
$followerName = $follower->profile->name;
$followerHabs = $follower->habs;
}
Get all habs from people he/she is following
foreach($user->following as $following)
{
$followingEmail = $following->email;
$followingName = $following->profile->name;
$followingHabs = $following->habs;
}
Habs
table the posts table? – SamV