This one is quite hard to explain and word, so i apologise if the title doesn't make sense!
Basically at the moment I have a pivot table like this
ID | USER_ID | FRIEND_ID
1 | 1 | 2
2 | 5 | 10
3 | 2 | 5
4 | 3 | 9
5 | 5 | 4
And I can get all of the friends for a user by having my relationship like this
public function user_friends(){
return $this->belongsToMany('App\Friends', 'user_friend', 'USER_ID', 'FRIEND_ID');
}
I want to be able to access all of my friends friends recursively in the cleanest way possible by referencing 1 id.
For example, if i get the user with an id of 1 and call the above user_friends
method, it would return friend with an id of 2 and that is it.
But friend 2 also has a friend with the id of 5, and id 5 has friends with the id's of 10 and 4, and so on, so i also want to get all of those as-well.
Basically by calling a single user id, I want to get each of the friends that are directly linked to user 1, then recursively get each of their friends, and so on and so forth until I have all of the friends that can be linked to user 1 in some way, shape or form.
Is this possible?