コード例 #1
0
 public static function getUsersString($id)
 {
     $result = "";
     $_users = ConversationUser::where(['conversation_id' => $id])->get(['user_id']);
     $users = User::whereIn('id', $_users)->get();
     foreach ($users as $user) {
         if ($user->id != Auth::id()) {
             $result = $result . $user->name . " " . $user->surname . ", ";
         }
     }
     return rtrim($result, ", ");
 }
コード例 #2
0
 public function store(Request $request, $id)
 {
     //
     //
     $conversation = Conversation::find($id);
     $conversation->touch();
     $input = Request::all();
     $input['published_at'] = Carbon::now();
     $input['author_id'] = Auth::id();
     $input['conversation_id'] = $id;
     Message::create($input);
     $to_users = ConversationUser::where('conversation_id', $id)->where('user_id', '!=', Auth::id())->get(['user_id']);
     foreach ($to_users as $_user) {
         $user = User::find($_user->user_id);
         $user->newNotification()->withType('message')->withSender(Auth::id())->withSubject($conversation->title)->withBody($input['body'])->regarding($conversation)->deliver();
     }
     return redirect('/messages/' . $id);
 }
コード例 #3
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;
 }