Пример #1
0
 public function hasConversation($id)
 {
     $user = Auth::user();
     $receiver = User::where('id', $id)->first();
     $userConversations = ConversationUser::where('user_id', '=', $user->id)->get(['conversation_id']);
     $receiverAndUserCommon = ConversationUser::where('user_id', $receiver->id)->whereIn('conversation_id', $userConversations)->get(['conversation_id']);
     if (!$receiverAndUserCommon->isEmpty()) {
         $otherConversations = ConversationUser::whereNotIn('user_id', array($user->id, $receiver->id))->get(['conversation_id']);
         $privateConversation = ConversationUser::whereIn('conversation_id', $receiverAndUserCommon)->whereNotIn('conversation_id', $otherConversations)->first();
         if ($privateConversation) {
             return $privateConversation;
         }
         return false;
     }
     return false;
 }