-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get unrelated users #94
Comments
I'm currently using it like this: $users = $user->doesntHaveFriendships()
->where('id', '<>', $user->id)
->inRandomOrder()
->take($limit )
->get(); I added in my App\Models\User.php model: public function invertedFriends()
{
$friendshipModelName = Interaction::getFriendshipModelName();
return $this->morphMany($friendshipModelName, 'recipient');
}
public function scopeDoesntHaveFriendships(Builder $builder)
{
return $builder->whereDoesntHave('friends')
->whereDoesntHave('invertedFriends');
} But I wouldn't want to have additional methods in the model. Any suggestion? |
The same need happens to list the publications of the user and friends: $user = auth()->user();
$publications = Publication
::where(function (Builder $query) use ($user) {
$query->whereHas('user.friends', function (Builder $query) {
$query->where('status', Status::ACCEPTED);
})->orWhereHas('user.invertedFriends', function (Builder $query) {
$query->where('status', Status::ACCEPTED);
})->orWhere('user_id', $user->id);
})
... It is necessary to use invertedFriends from the User.php model. The ideal would be something like: $user = auth()->user();
$publications = Publication
::where(function (Builder $query) use ($user) {
$query->whereHas('user.friends', function (Builder $query) {
$query->where('status', Status::ACCEPTED);
})->orWhere('user_id', $user->id);
})
... |
Did you ever figure this out? I'm trying to implement something similar. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How could I get a list of unrelated users. I need to put together a list of friendship suggestions.
Thanks!
The text was updated successfully, but these errors were encountered: