laravel - 在 laravel 友谊系统中合并两个集合
问题描述
我想在仪表板上显示所有用户,如果我向任何用户发送请求,它的状态应该是“已请求”,或者如果某个用户向我发送请求状态应该是“待定”,否则其他用户的状态应该是“发送请求”。我的控制器是
$users2 = User::with([
'sentRequests' => function ($query) {
}
])
->with([
'recievedRequests' => function ($query) {
}
])
->where('users.id', Auth::id())
->get();
$users3 = User::where('users.id','!=',Auth::id())
->get();
$users = $users2->merge($users3);
我的模型
public function sentRequests()
{
return $this->belongsToMany('App\User', 'friendships', 'user_id', 'friend_id');
}
public function recievedRequests()
{
return $this->belongsToMany('App\User', 'friendships', 'friend_id', 'user_id');
}
但问题出在 $users3 中,它返回了那些在 sentRequests 或 recievedRequests 中已经可见的用户
解决方案
推荐阅读
- java - 如何使用java检查json文件中是否存在json对象?
- java - 从 Java 源代码中找出使用的类和方法
- python - 如何剪切部分文本并用 Python 和 RegEx 替换每一行
- python - 错误:过时的元素引用:当我运行表格时,元素未附加到页面文档
- f# - F# 惯用的 async while 循环累加转换
- amazon-web-services - 如何使用 AWS CLI 启用 S3 对象日志记录到 Cloud Trail?
- java - 如何在java中将大型java对象存储和读取到hardrive而不是堆内存
- javascript - AMP 分析跟踪不发送事件
- drools - 从 Drools 对象的所有日期中查找最近的日期
- python - 如何将列表转换为 python 数据框