コード例 #1
0
 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!']);
 }