/** * Games * Sport * Finance * Animals */ $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); });
public function getChatroomById($id) { $chatrooms = Chatroom::find($id); return view('chatrooms.room', compact('chatrooms')); }