您好我的请求有问题。如何使这些功能不会返回第二个中存在的数据。恩。 user_id = 1 friend_id = 2来自sendedRequests,user_id = 2,friend_id = 1来自pendingRequests。
以下是代码:
public function showSendedRequests(){
$request = DB::table('friends_users')
->join('users', 'users.id', '=', 'friends_users.friend_id')
->where('who_send', $this->id)
->where('user_id', $this->id)
->where('accepted',false)
->get();
return $request;
}
public function showPendingRequests(){
$request = DB::table('friends_users')
->join('users', 'users.id', '=', 'friends_users.user_id')
->where([['friend_id', '=',Auth::user()->id],['accepted', '=',false],['who_send','!=',Auth::user()->id]])
->get();
return $request;
}
答案 0 :(得分:0)
您可以使用<>
不等于
$request = DB::table('friends_users')
->join('users', 'users.id', '=', 'friends_users.friend_id')
->where('who_send', $this->id)
->where('user_id','<>', $this->id)
->where('accepted',false)
->get();
return $request;
}
//for the next function
$request = DB::table('friends_users')
->join('users', 'users.id', '=', 'friends_users.user_id')
->where([['friend_id', '=',Auth::user()->id],['accepted', '=',false],['who_send','<>',Auth::user()->id]])
->get();
return $request;
}
进一步reference