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 // )); }