/** * 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('评论发表失败!'); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { $this->validate($request, ['content' => 'required']); $id = $request->input('parent_id'); $commentInfo = Comment::find($id); $userInfo = $request->user(); try { $data = ['el_id' => $commentInfo->el_id, 'type_id' => $commentInfo->type_id, 'username' => $userInfo->name, 'email' => $userInfo->email, 'parent_id' => $id, 'content' => $request->input('content')]; Comment::create($data); Notification::success('回复成功'); return redirect()->route('backend.comment.index'); } catch (\Exception $e) { return redirect()->back()->withErrors(array('error' => $e->getMessage()))->withInput(); } }
/** * 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); } }
public function publishComment() { $request = Request::capture(); $token = $request->input('token'); $content = $request->input('content'); $answerId = $request->input('answerId'); if ($content == null) { return Utility::response_format(Utility::RESPONSE_CODE_Error, '', '内容不能为空'); } $userId = AuthController::getUserIdByToken($token); if ($userId == null) { return Utility::response_format(Utility::RESPONSE_CODE_AUTH_ERROR, '', '认证失败'); } try { $comment = Comment::create(['comment_content' => $content, 'answer_id' => $answerId, 'user_id' => $userId, 'comment_time' => time()]); return Utility::response_format(Utility::RESPONSE_CODE_SUCCESS, '', '发布成功'); } catch (Exception $e) { return Utility::response_format(Utility::RESPONSE_CODE_DB_ERROR, '', $e->getMessage()); } }
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); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response * Lưu comment mới vào CSDL */ public function store(Request $request) { $comment = Comment::create(array('user' => $request->user, 'text' => $request->text, 'email' => $request->email, 'news_id' => $request->news_id, 'created_at' => date('Y-m-d H:i:s'))); return Response::json($comment); }
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); }