public function newComment(CommentFormRequest $request) { $comment = new Comment(array('post_id' => $request->get('post_id'), 'content' => $request->get('content'))); $comment->save(); // return redirect()->back()->with('status', 'Your comment has been created!'); return redirect()->back()->with('status', 'Your comment has been created!'); }
public function actionDelete() { $id = $_GET['id']; $comment = new ModelComment(); $comment->id = $id; $comment->delete(); header('Location: /admin'); }
/** * Post a comment on a blog post * POST * * @param Request $request * @param int $id * @param string $title * @return Response */ public function postComment(Request $request, $id, $title) { $this->validate($request, ['comment' => 'required']); $comment = new BlogCommentManager(); $comment->author = \Auth::user()->guid; $comment->date = date('Y-m-d H:i:s'); $comment->blog_id = $id; $comment->text = nl2br($request->comment); $comment->save(); return redirect()->route('blog.view', [$id, $title]); }
public function index() { //总访问量 $visits = \Cache::get('visits', 0); //今日注册用户 $todayUsers = User::today()->count('user_id'); //总用户数 $totalUsers = User::count('user_id'); //管理员聊天记录 $chatMessages = AdminMessage::with('admin')->limit(10)->oldest()->get(); //最新留言 $guestBook = GuestBook::with('user')->limit(10)->oldest()->get(); //最新注册用户 $users = User::limit(24)->oldest()->get(); //最新评论 $comments = Comment::limit(10)->oldest()->get(); // 总会员数量/待审核会员/普通会员/高端会员 $user_all_num = User::count('user_id'); $user_shenhe_num = User::status(\App\Enum\User::STATUS_CHECK)->count('user_id'); $user_level1_num = User::level(\App\Enum\User::LEVEL_1)->count('user_id'); $user_level3_num = User::level(\App\Enum\User::LEVEL_3)->count('user_id'); // 自我介绍待审核数量 $user_info_num = UserInfo::where('introduce_status', \App\Enum\User::INTRODUCE_CHECK)->count('user_id'); // 会员相片审核数量 $user_gallery_num = DB::table('user_gallery')->where('status', '待审核')->where('image_url', '!=', '')->count('photo_id'); // 文章数量 $article_num = DB::table('articles')->count('article_id'); $res = array('user_all_num' => $user_all_num, 'user_shenhe_num' => $user_shenhe_num, 'user_level1_num' => $user_level1_num, 'user_level3_num' => $user_level3_num, 'user_info_num' => $user_info_num, 'user_gallery_num' => $user_gallery_num, 'article_num' => $article_num); return $this->view('index', $res); // return $this->view('index')->with('visits', $visits)->with('todayUsers', $todayUsers)->with('totalUsers', // $totalUsers)->with('chatMessages', $chatMessages)->with('guestBook', $guestBook)->with('users', // $users)->with('comments', $comments); }
public function addComment(\app\model\Comment $comment) { $successfulComment = false; $comments = $this->getAllComments(); try { $db = $this->db->getConnection(); $sql = "INSERT INTO {$this->dbTable} (" . self::$commenterColumn . ", " . self::$contentColumn . ", " . self::$venueIdentifierColumn . ", " . self::$timeStampColumn . ") VALUES (?, ?, ?, ?)"; $params = array($comment->getName(), $comment->getContent(), $comment->getVenueIdentifier(), $comment->getTimeStamp()); $query = $db->prepare($sql); $query->execute($params); $successfulComment = true; } catch (\PDOException $e) { die("Database error, please try again later"); } return $successfulComment; }
private function saveComment($request) { $comment = new Comment(); $user = $this->userSession->getUser(); $user = $this->em->find("App\Model\User", $user->getId()); $comment->setUser($user); $comment->setComment($request->get('comment')); $post = $this->em->find("App\Model\Post", $request->get('postId')); $post->setCommentsNum($post->getCommentsNum()+1); $comment->setPost($post); $comment->setPostedAt(new \DateTime('now')); $this->em->persist($comment); $this->em->flush(); return $comment; }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $data = \Request::all(); $data['user_id'] = \Auth::user()->id; $result = \App\Model\Comment::create($data); return back()->with('name', 'comment'); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(Comment $result) { $attributes = $result->all(); $attributes['type_id'] = 0; if (!captcha_check($attributes['captcha'])) { Notification::error('验证码错误'); return redirect()->route('article.show', ['id' => $attributes['el_id'], '#commentList'])->withInput(); } unset($attributes['captcha']); if (Session::token() !== $attributes['_token']) { Notification::error('token错误'); return redirect()->route('article.show', ['id' => $attributes['el_id'], '#commentList'])->withInput(); } unset($attributes['_token']); try { $attributes['content'] = htmlspecialchars($attributes['content']); CommentModel::create($attributes); ArticleStatus::updateCommentNumber($attributes['el_id']); Notification::success('评论成功'); return redirect()->route('article.show', ['id' => $attributes['el_id'], '#commentList']); } catch (\Exception $e) { Notification::error($e->getMessage()); return redirect()->route('article.show', ['id' => $attributes['el_id'], '#commentList'])->withInput(); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { if (Comment::create(Input::all())) { return Redirect::back(); } else { return Redirect::back()->withInput()->withErrors('评论发表失败!'); } }
public function actionIndex() { $view = new View(); $view->title = 'Blog | Admin'; // $comments = Comment::getAll(); $view->comments = Comment::getAll(); $view->users = User::getAll(); $view->displayPage('admin/index'); }
public function actionOne() { $id = $_GET['id']; // If a comment has been sent: if ($this->isPost()) { $comm = new ModelComment(); // fields cannot be empty! $success = $comm->fill(['article_id' => $id, 'author' => htmlspecialchars($_POST['author']), 'text' => htmlspecialchars($_POST['text'])]); $success ? $comm->save() : ($_SESSION['error'] = 'Fill all fields!'); header('Location: /article/one?id=' . $id . '#comment'); exit; } // Getting the particular article: $item = ModelArticle::getOneById($id); $this->isFound($item); $comments = ModelComment::getByColumn('article_id', $id); $view = new View(['item' => $item, 'comments' => $comments, 'title' => $item->title]); $view->displayPage('articles/one'); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { // $article = Article::getArticleModelByArticleId($id); $tags = Tag::getTagModelByTagIds($article->tags); $authorArticle = Article::getArticleModelByUserId($article->user_id); $commentList = Comment::getCommentListModel($id); $data = array('article' => $article, 'tags' => $tags, 'authorArticle' => $authorArticle, 'commentList' => $commentList); viewInit(); return homeView('article', $data); }
/** * Handle the event. * * @param CommentSendEmail $event * @return void */ public function handle(CommentSendEmail $event) { // if ($event->parentId != 0) { $parent = Comment::find($event->parentId); if (!empty($parent)) { Mail::send('emails.comment', ['username' => $parent->username, 'id' => $parent->el_id], function ($message) use($parent) { $message->to($parent->email, $parent->username)->subject('您的评论被回复了'); }); } } }
public function show($id) { if (is_null($id)) { return view('errors.404'); } $post = Post::with('user')->find($id); if (!$post) { return view('errors.404'); } $comments = Comment::with('user')->where('post_id', $id)->orderBy('created_at', 'desc')->paginate(5); $this->viewData['post'] = $post; $this->viewData['comments'] = $comments; return view('posts.show', $this->viewData); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { if ($request->ajax()) { $result = ['html' => '', 'msg' => 'Something went wrong', 'success' => false]; $input = $request->input(); $validation = Validator::make($request->all(), Comment::$validation, Comment::$messages); if ($validation->fails()) { $errors = $validation->messages(); $result['msg'] = get_message_from($errors); return response()->json($result); } $input['user_id'] = $this->currentUser->id; $comment = Comment::create($input); if (!$comment) { $result['msg'] = 'Can not post your comment'; } else { $result = ['html' => view('comments._a_comment', ['comment' => $comment])->render(), 'msg' => 'Posted your comment', 'success' => true]; } return response()->json($result); } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $comment = Comment::find($id); $comment->delete(); return Redirect::to('admin/comments'); }
public function getAnswerDetail() { $request = Request::capture(); $token = $request->input('token'); $answerId = $request->input('answerId'); $userId = AuthController::getUserIdByToken($token); if ($userId == null) { return Utility::response_format(Utility::RESPONSE_CODE_AUTH_ERROR, '', '认证失败'); } if ($answerId == null) { return Utility::response_format(Utility::RESPONSE_CODE_Error, '', 'answerId不能为空'); } $answer = Answer::select('id', 'answer_content', 'answer_time', 'question_id', 'user_id', 'is_resolved')->where('id', $answerId)->first()->toArray(); // print_r($question); // 个人信息 $userInfo = UserInfo::select('user_name', 'head_pic')->where('user_id', $answer['user_id'])->first()->toArray(); $answer = array_merge($answer, $userInfo); // 图片 $picIds = AnswerPictures::select('pic_id')->where('answer_id', $answer['id'])->get()->toArray(); $pics = Picture::whereIn('id', $picIds)->get()->toArray(); $answer = array_merge($answer, ['image' => $pics]); // 评论数 $comments = Comment::where('answer_id', $answer['id'])->count(); $answer = array_merge($answer, ['commentNumber' => $comments]); // 赞数 $upCount = AnswerUp::where('answer_id', $answer['id'])->count(); $answer = array_merge($answer, ['upNumber' => $upCount]); return Utility::response_format(Utility::RESPONSE_CODE_SUCCESS, $answer, '请求成功'); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $comment = Comment::where('page_id', $id)->delete(); $page = Page::find($id)->delete(); return Redirect::to('admin'); }
/** * 显示评论列表页 * @return $this */ public function index() { $models = Comment::all(['comment_id', 'content', 'user_id', 'article_id', 'created_at']); $models->load(['user', 'article']); return $this->view('index')->with('models', $models); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response * Xóa một comment */ public function destroy($id) { Comment::destroy($id); return Response::json(array('success' => true)); }
public function removeCMTAction() { return Comment::removeCmt($_POST['id']); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { // if (Comment::destroy($id)) { Notification::success('删除成功'); } else { Notification::success('删除失败'); } return redirect()->back(); }
public function singleAction($id) { if ($entry = Entry::findOrFail($id)) { if ($postData = $this->getPostData()) { $postData['entry_id'] = $id; Comment::create($postData); return $this->redirect('singleEntry', array('id' => $id)); } $entry['username'] = User::where('id', strval($entry['user_id']))->first()['name']; $data['entry'] = $entry; $data['comments'] = Comment::where('entry_id', $id)->get(); } else { $data['error'] = 'Không tìm thấy bài viết'; } return $this->render('entry/single.html.twig', $data); }
public function removeCmt($id) { return Comment::where('id', $id)->delete(); }
public function testHasManySave() { $user = User::read(3); $comment1 = Comment::create(['text' => 'create']); $comment2 = Comment::newRecord(['text' => 'new record']); $user->Comment[] = $comment1; $user->Comment[] = $comment2; $this->assertEquals(true, $user->save()); $this->assertEquals($user->id, $comment1->user_id); $this->assertEquals($user->id, $comment2->user_id); $this->assertEquals('create', $user->Comment[0]->text); $this->assertEquals('new record', $user->Comment[1]->text); /* * 本当に保存できたかreadで確認 */ $savedComment1 = Comment::read($user->Comment[0]->id); $savedComment2 = Comment::read($user->Comment[1]->id); $this->assertEquals('create', $savedComment1->text); $this->assertEquals('new record', $savedComment2->text); $this->assertEquals($user->id, $savedComment1->user_id); $this->assertEquals($user->id, $savedComment2->user_id); }