Friends is a pivot table code is
public function friends() {
return $this->belongsToMany('Trinity\Users\User', 'friends', 'user_id', 'friend_id');
}
Have you ever tried this?
$friend = User::whereHas('friends', function($query) use ($id, $user)
{
$query->where('friend_id', '=', $id)->where('user_id', '=', $user);
})->count();
But there is an option that, user_id is the visiting user id or the other way around.
I see your point.
Make this change:
$query->where('friend_id', '=', $id)->where('user_id', '=', $user)->orWhere('friend_id', '=', $user)->where('user_id', '=', $id);
I got it working with this
$friend = $this->friends()->where('friend_id', '=', $id)->where('user_id', '=', $user)->orWhere('friend_id', '=', $user)->where('user_id', '=', $id)->first();
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community