public function run() { CommentOfTopiccomment::create(['sender_id' => 1, 'receiver_id' => 2, 'topiccomment_id' => 1, 'topic_id' => 2, 'content' => '戏剧带给你不一样的生活体验,发扬传统文化,传承中国文明,应好好珍惜现在的好时代,去到外面,漂洋过海。']); CommentOfTopiccomment::create(['sender_id' => 1, 'receiver_id' => 3, 'topiccomment_id' => 1, 'topic_id' => 2, 'content' => '戏剧带给你不一样的生活体验,发扬传统文化,传承中国文明']); CommentOfTopiccomment::create(['sender_id' => 3, 'receiver_id' => 1, 'topiccomment_id' => 2, 'topic_id' => 2, 'content' => '发扬传统文化,传承中国文明']); CommentOfTopiccomment::create(['sender_id' => 2, 'receiver_id' => 1, 'topiccomment_id' => 2, 'topic_id' => 2, 'content' => '发扬传统文化,传承中国文明']); }
public function getOneTopic() { //获取最新的那个话题 $topic = Topic::orderBy('updated_at', 'desc')->first(); // dd($topic->id); if ($topic != null) { //话题人的信息 $user_id = $topic->user_id; $user = User::find($user_id); //话题评论 $topic_comments = $topic->hasManyTopicComments()->get(); // $comment_name = array(); $comment_replys = array(); if ($topic_comments != null) { $commentCount = $topic_comments->count(); foreach ($topic_comments as $topic_comment) { //评论的回复人信息的对象集合 //replys可能为空数组 $replys = CommentOfTopiccomment::where('topiccomment_id', '=', $topic_comment->id)->orderBy('created_at', 'asc')->get(); $key = $topic_comment->id; $comment_replys[$key] = $replys; } return View::make('communication.topics')->with(array('topic' => $topic, 'topic_comments' => $topic_comments, 'comment_replys' => $comment_replys, 'commentCount' => $commentCount, 'user' => $user, 'links' => $this->link())); } } return View::make('communication.topics')->with('links', $this->link()); // ->with(array( // 'topic' => $topic, // 'topic_comments' =>$topic_comments, // 'commentCount' => $commentCount, // 'comment_name' => $comment_name, // 'user' => $user // )); }
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)); }