/** * Send a reply * * @param int $id * @return Response */ public function reply($id) { $chat = Chat::findOrfail($id); $chat->last_reply = date("Y-m-d H:i:s"); $chat->save(); $reply = new Reply(); $reply->text = Input::get('text'); $reply->chat_id = $chat->id; $reply->user_id = Auth::user()->id; $reply->save(); //Set up notifications for this chat foreach ($chat->user()->get() as $user) { $reply->notification()->save($user); } $notification = Notification::where('user_id', '=', Auth::user()->id)->where('reply_id', '=', $reply->id)->firstOrFail(); $notification->has_read = 1; $notification->save(); return Redirect::to('/community/chats/' . $id)->with('flash_chat', 'Your chat has been sent!')->with('alert_class', 'alert-success'); }