[英]Display comments to the page
I have a problem posting comments on the page depending on the posting id.根据发布 ID,我在页面上发布评论时遇到问题。
Controller: Controller:
public function viewUserQuestion(Post $post) {
$comment = Comment::where('post_id', $post->id)->get();
return view('viewQuestion', compact('post','comment'));
}
Route:路线:
Route::get('/viewUserQuestion/{post}', 'PostsController@viewUserQuestion')->name('viewQuestion');
View:看法:
@foreach($post->comments as $comment)
<span class="m-b-15 d-block" align="center">
{!! $comment->commentText !!}
</span>
@endforeach
What do you think will be the problem?你认为会是什么问题? Do you think I'm making the wrong display or?你认为我做错了展示还是?
at this side在这一边
change改变
return view('viewQuestion', compact('post','comment'));
to至
return view('viewQuestion', ['comment'=>$comment]);
and change the view to并将视图更改为
@foreach($comment as $comment)
<span class="m-b-15 d-block" align="center">
{!! $comment->commentText !!}
</span>
@endforeach
hope this help:)希望这有帮助:)
Change your code like below it will work perfectly.像下面这样更改您的代码,它将完美运行。
Controller: Controller:
public function viewUserQuestion(Post $post) {
$comments = Comment::where('post_id', $post->id)->get();
return view('viewQuestion', compact('comments'));
}
View:看法:
@foreach($comments as $comment)
<span class="m-b-15 d-block" align="center">
{!! $comment->commentText !!}
</span>
@endforeach
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.