/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy(Chat $chat, Request $request) { $user = JWTAuth::parseToken()->authenticate(); if (!$chat->users()->whereType('admin')->whereUserId($user->id)->exists()) { return response()->json(['status' => 'failure', 'message' => 'Access denied.'], 403); } // $audience = User::whereIn('id', explode(',', $request->get('audience')))->get(); $this->dispatch(new DeleteChatRoom($user, $chat)); return response()->json(['status' => 'success', 'message' => 'Chat Deleted.']); }
public function sendMsg(Request $request) { if (!isset($_SESSION['user_id'])) { return $this->index(); } $message = filter_var(trim($request->input('user_msg')), FILTER_SANITIZE_MAGIC_QUOTES); if (!empty($message)) { $Chat = new Chat($_SESSION['user_id'], $message); $Chat->save(); } }
/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create($id, Request $request) { // return 'jej'; $message = new Chat(); $message->message = $request->input('input'); $message->sender_id = Auth::user()->id; $message->receiver_id = $id; // var_dump($message); // return 'jej'; $message->save(); return response()->json($message); }
public function postChat(Request $request) { $user = Auth::user(); if ($request->input('message') !== '') { $chat = new Chat(); $chat->message = $request->input('message'); $chat->user_id = $user->id; $chat->save(); $status = 'message posted!'; } else { $status = 'message is blank'; } return redirect('/leaderboards')->with('status', $status); }
public function track() { if (!array_key_exists(28, $this->data) || $this->data[28] == NULL) { return; } $chatMsg = $this->data[28]; if ($chatMsg == NULL || $chatMsg == "" || strlen($chatMsg) == 0) { return; } $chat = new Chat(); $chat->message = $chatMsg; $chat->save(); exit; }
/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update(Request $request, $id) { $c = Chat::findOrNew($id); $input = $request->all(); $c->fill($input)->save(); return ["success" => true]; }
/** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { $this->user = JWTAuth::parseToken()->authenticate(); $chatId = $this->route('chat'); $chat = Chat::findOrFail($chatId); if ($chat) { return $chat->users()->whereUserId($this->user->id)->whereType('admin')->exists(); } }
/** * 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); }
/** * Execute the command. * * @return void */ public function handle() { $chat = Chat::create($this->data); $this->user->chats()->save($chat, ['type' => 'admin']); if ($this->project) { $this->project->chats()->save($chat); } event(new FeedableEvent('ChatRoomCreated', $this->user, $chat, null, $this->project, $this->audience)); return $chat; }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { //Grab all the data we need to instead into the row $auth = new Auth(); $user_id = $auth::user()->id; $input = Input::all(); $param = array("user_id" => $user_id, "message" => $input['message']); //Create the row in the database $result = Chat::create($param); $result['name'] = $auth::user()->name; if (is_object($result)) { return json_encode($result); } 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 testFiresNothingWhenCommandDoesNotExist() { $msg = json_encode(['command' => 'my-other-command-that-does-not-exist']); $this->chat->onMessage($this->connection, $msg); $this->assertFalse($this->commandExecuted); }
public function ajaxNotification() { $total = Chat::count(); $ultimo_chat = Chat::orderBy('created_at', 'desc')->first(); if ($total > 0) { $url = route('visualizar-chat', [$ultimo_chat->id]); return response()->json(['total' => $total, 'title' => $ultimo_chat->nome, 'message' => $ultimo_chat->mensagem, 'url' => $url]); } return response()->json(['total' => $total, 'title' => '', 'message' => '', 'url' => '']); }
public function stestJoinChat() { $user = User::firstOrFail(); $chat = Chat::create($this->chatroomdata); $action = Bus::dispatch(new JoinChat($user, $chat)); // add $this->assertNull($action->admin); $this->assertTrue($chat->users->contains($user->id)); $this->assertEquals(1, $chat->messages->count()); $this->assertEquals(1, $chat->users->count()); $action = Bus::dispatch(new LeaveChat($user, $chat)); // remove $this->assertEquals(2, Message::count()); // $this->assertEquals(0, $chat->users->count()); $admin = User::all()->last(); $this->assertNotNull($admin); $this->assertNotEquals($admin->id, $user->id); $action = Bus::dispatch(new JoinChat($user, $chat, $admin)); // add $this->assertEquals($action->admin->id, $admin->id); $action = Bus::dispatch(new LeaveChat($user, $chat, $admin)); // remove }
/** * Return Server chats */ public function getServerChats() { $chats = Chat::orderBy('created_at', 'DESC')->limit(25)->get(); foreach ($chats as $chat) { print $chat->message . "<br>"; } }
$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 postMsg(Request $request) { Chat::create($request->input()); }