コード例 #1
0
 /**
  * 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();
     }
 }
コード例 #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Requests\Comment $request, Post $post)
 {
     $comment = new Comment($request->all());
     $post->comments()->save($comment);
     return redirect($post->slug);
 }
コード例 #3
0
ファイル: PostRequest.php プロジェクト: TyrekeYang/webapp
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $id = $this->route('id');
     return Comment::where('id', $id)->where('user_id', \Auth::id())->exists();
 }