示例#1
0
 /**
  * Created By Dara on 8/2/2016
  * add reply to comment
  */
 public function session(Session $session, $comment_id, Request $request)
 {
     $user = $this->user;
     $this->validate($request, ['content' => 'required']);
     if ($comment_id) {
         //check if the comment has been set or not (reply) level 2 comment
         $comment = Comment::findOrFail($comment_id);
         $parent_id = $comment->id;
         $msg = trans('users.answerSent');
         $nested = true;
     } else {
         //level 1 comment
         $parent_id = 0;
         $msg = trans('users.commentSent');
         $nested = false;
     }
     //add comment to db
     $newComment = $session->comments()->create(['user_id' => $user->id, 'content' => $request->input('content'), 'parent_id' => $parent_id]);
     $numComment = $session->comments()->count();
     $session->update(['num_comment' => $numComment]);
     $obj = $session;
     $model = 'session';
     return ['hasCallback' => 1, 'callback' => 'session_comment', 'hasMsg' => 1, 'msgType' => '', 'msg' => $msg, 'returns' => ['newComment' => view('comment.comment', compact('newComment', 'session', 'user', 'obj', 'model'))->render(), 'nested' => $nested, 'numComment' => $numComment]];
 }