/** * Display a listing of the resource. * * @return Response */ public function index() { if (Input::has('search')) { $query = Input::get('search'); $chats = Chat::where('message', 'LIKE', "%{$query}%")->orderBy('created_at', 'DESC')->paginate(50); } else { $chats = Chat::orderBy('created_at', 'DESC')->paginate(50); } return view('chat.index')->withChats($chats); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index($id) { $messages = Chat::where('sender_id', '=', $id)->orwhere('receiver_id', '=', $id)->get(); foreach ($messages as $message) { $message->sender = $message->sender()->first(); // $message->sender->pic = $message->sender()->pictures()->first() } // var_dump($messages); return response()->json($messages); }
public function getStream() { $lmsg = session('lmsg'); $msgs = Chat::where('id', '>', $lmsg->id)->get(); header('Content-Type: text/event-stream'); header('Cache-Control: no-cache'); if (!$msgs->isEmpty()) { session(['lmsg' => $msgs->last()]); echo "data: {\n"; foreach ($msgs as $key => $msg) { echo "data: \"{$key}\": {\"name\": \"{$msg->name}\", \"msg\": \"{$msg->message}\", \"created_at\": \"{$msg->created_at}\"}\n"; } echo "data: }\n\n"; } flush(); }
$app->get('chatrooms/{category}', function ($category) { $chatrooms = Chatroom::where('category', $category)->get(); return $chatrooms; }); $app->post('chatrooms', function (Request $request) { $chatroom = Chatroom::create($request->all()); return $chatroom; }); $app->post('chatrooms/{id}/chat', function (Request $request, $chatroomId) { $chatroom = Chatroom::find($chatroomId); $chat = new Chat($request->all()); $chatroom->chats()->save($chat); return $chat; }); $app->get('chatrooms/{id}/chat', function ($chatroomId) { return Chat::where('chatroom_id', $chatroomId)->get(); }); $app->post('login', function (Request $request) { $username = $request->input('username'); $password = $request->input('password'); if (areCredentialsCorrect($username, $password)) { return response()->json(["message" => "Login successful"], 200); } return response()->json(["message" => "Credentials are incorrect"], 400); }); function areCredentialsCorrect($username, $password) { if ($username == "boyd" && $password == "boyd" || $username == "bas" && $password == "bas") { return true; } return false;
public function deleteConversation(Request $request) { //Checks if required parameters are provided if (!$request->from_user_id || !$request->to_user_id) { return Response::json(["status" => "ERROR", "response" => "Conversation fetching failed"], 400); } $fromUser = User::where('id', $request->from_user_id)->first(); $toUser = User::where('id', $request->to_user_id)->first(); //Checks if from and to user exists if (!$fromUser || !$toUser) { return Response::json(["status" => "ERROR", "response" => "Conversation fetching failed"], 400); } //Delete whole conversation from database $chat = Chat::where(function ($query) use($request) { $query->where('from_user_id', $request->from_user_id)->where('to_user_id', $request->to_user_id); })->orWhere(function ($query) use($request) { $query->where('from_user_id', $request->to_user_id)->where('to_user_id', $request->from_user_id); })->delete(); //Reply return Response::json(["status" => "OK", "response" => $chat], 200); }
public function edit($id) { $chat = Chat::where('id', '=', $id)->first(); return view('admin.chat.visualizar', ['chat' => $chat]); }