如果frienship在laravel中处于挂起状态,则用户无法发送好友请求

如果frienship在laravel中处于挂起状态,则用户无法发送好友请求,laravel,Laravel,我正在尝试创建一个在拉拉维尔的社交网站。首先,我加载除我之外的所有用户 并以这种方式从数据库中加载友谊状态 $users = User::with([ 'friendships' => function ($query) { $query->where('sender_id', Auth::id()); $query->where('recipient_id',Auth::user()-&g

我正在尝试创建一个在拉拉维尔的社交网站。首先,我加载除我之外的所有用户 并以这种方式从数据库中加载友谊状态

$users = User::with([
            'friendships' => function ($query) {
                $query->where('sender_id', Auth::id());
                $query->where('recipient_id',Auth::user()->id);
            }

        ])
        ->where('users.id', '!=', Auth::id())
        ->get();
我有一个这样的用户列表

name      email                 status
roger     roger@gmail.com       requested
alex      alex@gmail.com        send request
....
我只想知道关于这个主题的最后一件事,目前我加载所有用户及其状态,但如果有用户向我发送朋友请求,则我视图中的状态栏应为“我待决”,在该栏中,我只能接受他的请求,并且在我取消他的请求之前不能向他发送任何fried请求。 正如您在facebook中所看到的,删除$query->where('sender_id',Auth::id());您的查询条件是发件人id和收件人id具有相同的id