/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $article_id = $request->input('article_id'); $contributor_id = $request->input('contributor_id'); $message = $request->input('comment'); $comment = new Comment(); $comment->article_id = $article_id; $comment->contributor_id = $contributor_id; $comment->comment = $message; $result = $comment->save(); return response()->json(['request_id' => uniqid(), 'status' => $result ? 'success' : 'failure', 'timestamp' => Carbon::now()], $result ? 200 : 500); }
/** * Store a newly comment in storage. * * @param \Illuminate\Http\Request * @param $slug * @return \Illuminate\Http\Response */ public function store(Request $request, $slug) { $rules = ['comment' => 'required|max:2000']; $validator = Validator::make($request->all(), $rules); if ($validator->fails()) { $this->throwValidationException($request, $validator); } $article = Article::whereSlug($slug)->firstOrFail(); $comment = new Comment(); $comment->contributor_id = Auth::user()->id; $comment->article_id = $article->id; $comment->comment = $request->input('comment'); if ($comment->save()) { return redirect(route('article.show', [$slug]) . '#form-comment')->with(['status' => 'success', 'message' => Lang::get('alert.comment.send')]); } return redirect()->back()->withErrors(['error' => Lang::get('alert.error.database')]); }