コード例 #1
0
 /**
  * Add reply to a post
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $post = Post::find($id);
     if (!isset($post->p_id)) {
         return Response::json(['result' => 2001, 'data' => [], 'info' => '您回复的帖子不存在']);
     }
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     $to_user = Input::get('to', 0);
     $content = Input::get('content', '');
     $reply = new PostsReply();
     $reply->p_id = $id;
     $reply->r_content = $content;
     $reply->r_status = 1;
     $reply->to_u_id = $to_user;
     $reply->created_at = date('Y-m-d H:i:s');
     try {
         $this->_user = User::chkUserByToken($token, $u_id);
         $reply->u_id = $this->_user->u_id;
         $reply->addReply();
         $post->p_reply_count += 1;
         $post->save();
         $re = ['result' => 2000, 'data' => [], 'info' => '回复成功'];
     } catch (Exception $e) {
         $re = ['result' => 2001, 'data' => [], 'info' => $e->getMessage()];
     }
     return Response::json($re);
 }