Exemple #1
0
 public function seen(Request $request)
 {
     $user = Auth::user();
     $holder = $request->input('holder');
     Event::fire(new seenMessage($holder));
     MessageUser::where('parentable_type', 'App\\User')->where('parentable_id', $holder)->where('user_id', $user->id)->where('status', 0)->update(['status' => 1]);
 }
Exemple #2
0
 public function myChats()
 {
     $user = Auth::user();
     $send = MessageUser::where('parentable_id', $user->id)->where('parentable_type', 'App\\User')->where('user_id', '!=', $user->id)->groupBy('user_id')->get();
     $receive = MessageUser::where('user_id', $user->id)->where('parentable_id', '!=', $user->id)->where('parentable_type', 'App\\User')->groupBy('parentable_id')->get();
     $histories = $receive->merge($send);
     $histories = $histories->each(function ($history, $key) use($user) {
         if ($history->user_id == $user->id) {
             $history->friend_info = $history->parentable;
         } elseif ($history->parentable_id == $user->id) {
             $history->friend_info = $history->user;
         }
         $this->latest($history->friend_info->id);
         $history->latestMessage = $this->latestMessage();
         $history->latestCreatedAt = $this->latestCreatedAt();
         $history->latestHumanCreatedAt = jDate::forge($history->latestCreatedAt)->ago();
         $history->newMessagesCount = $this->newMessagesCount();
     })->sortByDesc('latestCreatedAt');
     $histories = $histories->groupBy(function ($item, $key) {
         return $item->friend_info->id;
     });
     return $histories;
 }