public function chatUpdate(Request $request)
 {
     //$id = $request->id;
     $room_id = $request->room_id;
     $chat_text = $request->text;
     $created_at = Carbon::now();
     $chat_id = RoomChat::max('id');
     $chat_id = $chat_id + 1;
     $query = ['id' => $chat_id, 'room_id' => $room_id, 'text' => $chat_text, 'created_at' => $created_at];
     //dd($query);
     RoomChat::insert($query);
     $room_data = RoomChat::where('room_id', '=', $room_id)->get();
     //return view('chat.room', compact('room_data'));
 }
Esempio n. 2
-1
 public function roomChat(Request $request)
 {
     if ($request->ajax()) {
         $room_id = $request->room_id;
         switch ($request->mode) {
             case 'commit':
                 $text = nl2br($request->text);
                 $query = ['room_id' => $room_id, 'user_id' => Auth::user()->id, 'text' => $text, 'created_at' => Carbon::now()];
                 $chat = RoomChat::create($query);
                 return ['self-message' => $this->roomSelfTextHtmlBuilder($chat), 'latest-chat-id' => $chat->id];
                 break;
             case 'receive':
                 $latest_chat_id = RoomChat::where('room_id', '=', $room_id)->latest('created_at')->pluck('id');
                 if ($latest_chat_id != $request->latest_chat_id) {
                     $chats = RoomChat::where('room_id', '=', $room_id)->where('id', '>=', $latest_chat_id)->get();
                     foreach ($chats as $chat) {
                         $chat['count-up'] = ChatMeta::where('meta_type', '=', 'count-up')->where('chat_id', '=', $chat->id)->count();
                         $chat['count-down'] = ChatMeta::where('meta_type', '=', 'count-down')->where('chat_id', '=', $chat->id)->count();
                     }
                     return ['message' => $this->memberTextHtmlBuilder($chats), 'latest-chat-id' => $latest_chat_id];
                 } else {
                     return 'false';
                 }
                 break;
         }
     }
     $room_id = $request->room_id;
     $chats = RoomChat::where('room_id', '=', $room_id)->orderBy('created_at')->get();
     $latest_receive_chat_id = RoomChat::where('room_id', '=', $room_id)->latest('created_at')->pluck('id');
     foreach ($chats as $chat) {
         $chat['count-up'] = ChatMeta::where('meta_type', '=', 'count-up')->where('chat_id', '=', $chat->id)->count();
         $chat['count-down'] = ChatMeta::where('meta_type', '=', 'count-down')->where('chat_id', '=', $chat->id)->count();
     }
     return view('chat.room', compact('chats', 'room_id', 'latest_receive_chat_id'));
 }