/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store($id) { $request = Request::all(); $comment = new Comment(); $comment->user()->associate(Auth::user()->id); $comment->article()->associate($request['articleID']); $comment->comment = $request['comment']; $comment->save(); return redirect('/articles/' . $request['articleID']); }
public function addComment(CommentRequest $request, Article $article) { $comment = new Comment(); $date = Carbon::now(); //$comment->setPublishedAtAttribute(); $comment->content = $request->get('content'); $comment->setPublishedAtAttribute(); $comment->article()->associate($article); $comment->user()->associate(Auth::user()); $comment->save(); if (!is_null($article)) { // dd($comment); flash()->overlay('Your Comment has been successfully added!', 'Good Job'); return redirect()->back(); } return redirect('articles')->withErrors(['Error:' => 'This article does not exit anymore!']); }