You don't need a UserUser model.
class User extends Eloquent{
public function followers(){//they follow this user
return $this->belongsToMany('User', 'user_user', 'id_user', 'id_userseguito');
}
public function followings(){//this user follows them
return $this->belongsToMany('User', 'user_user', 'id_userseguito', 'id_user');
}
}
Check if it works.
$user = User::find($id);
$followerNames = array();
foreach($user->followers as $follower){
$followerNames[] = $follower->username;
}
$followingNames = array();
foreach($user->followings as $following){
$followingNames[] = $following->username;
}
return array(
'user' => $user,
'followers' => $followerNames,
'followings' => $followingNames
);
De nada :P
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community