public function run()
 {
     TopicComment::create(['content' => '你这样说真的好吗?不知君何想如此,妙哉否,欢快否!', 'user_id' => 4, 'topic_id' => 2]);
     TopicComment::create(['content' => '你这样说真的好吗?不知君何想如此,妙哉否,欢快否!', 'user_id' => 3, 'topic_id' => 2]);
     TopicComment::create(['content' => '你这样说真的好吗?不知君何想如此,妙哉否,欢快否!', 'user_id' => 2, 'topic_id' => 2]);
 }
Beispiel #2
0
 public function reply()
 {
     if (!Auth::check()) {
         return Response::json(array('errCode' => 1, 'message' => '[权限禁止]请先登录'));
     }
     $user = Auth::user();
     $content = Input::get('content');
     $topic_id = Input::get('topic_id');
     $comment_id = Input::get('comment_id');
     $reply_id = Input::get('reply_id');
     $reply_type = Input::get('reply_type');
     $validation = Validator::make(array('content' => $content), array('content' => 'required'));
     if ($validation->fails()) {
         return Response::json(array('errCode' => 1, 'message' => '[参数错误]请填写回复内容!'));
     }
     $reply = new CommentOfTopiccomment();
     $reply->content = $content;
     $reply->topiccomment_id = $comment_id;
     $reply->topic_id = $topic_id;
     $reply->sender_id = $user->id;
     if ($reply_type == 0) {
         $reply->receiver_id = TopicComment::find($comment_id)->user_id;
     } else {
         $reply->receiver_id = CommentOfTopiccomment::find($reply_id)->sender_id;
     }
     if (!$reply->save()) {
         return Response::json(array('errrCode' => 2, 'message' => '[数据库错误]回复评论失败!'));
     }
     $reply["sender_avatar"] = $user->avatar;
     $reply["sender_name"] = $user->username;
     $reply["receiver_name"] = User::find($reply->receiver_id)->username;
     return Response::json(array('errCode' => 0, 'reply' => $reply));
 }