0
我在我的應用程序中有一個評論框,它的工作正常。但我想顯示在我的文章中發表評論的用戶,我該如何實現?到目前爲止,我有這個代碼。如何在評論中顯示用戶
這是我的看法
<div class="view-post">
<div class="body">
<h3>{{$posts->title}}</h3>
<h6>{{$posts->created_at->toFormattedDateString()}}</h6>
<p><img src="{{ asset('img/' . $posts->image) }}" class="img-rounded"/></p>
<p>{{$posts->content}}</p>
</div>
<hr>
<section>
<h5>LEAVE US A COMMENT</h5>
<form action="{{ URL::route('createComment', array('id' => $posts->id))}}" method="post">
<div class="form-group">
<input class="form-control" type="text" placeholder="Comment..." name="content">
</div>
<input type="submit" class="btn btn-default" />
</form>
</section><br>
<section class="comments">
@foreach($posts->comment as $comments)
<blockquote>{{$comments->content}}</blockquote>
@endforeach
</section>
</div>
我的控制器
public function viewPost($id)
{
$post = Post::find($id);
$user = Auth::user();
$this->layout->content = View::make('interface.viewPost')->with('posts', $post)->with('users',$user);
}
public function createComment($id)
{
$post = Post::find($id);
$comment = new Comment();
$comment->content = nl2br(Input::get('content'));
$post->comment()->save($comment);
return Redirect::route('viewPost', array('id' => $post->id));
}
所以除了從用戶到發佈和發佈評論關係,我必須這樣做? – 2015-02-24 15:20:11
我想是的。像這樣嘗試一次。 – Nick 2015-02-24 15:26:02