【发布时间】:2020-07-28 06:16:43
【问题描述】:
我在页面上发布 cmets 时遇到问题,具体取决于发布 ID。
控制器:
public function viewUserQuestion(Post $post) {
$comment = Comment::where('post_id', $post->id)->get();
return view('viewQuestion', compact('post','comment'));
}
路线:
Route::get('/viewUserQuestion/{post}', 'PostsController@viewUserQuestion')->name('viewQuestion');
查看:
@foreach($post->comments as $comment)
<span class="m-b-15 d-block" align="center">
{!! $comment->commentText !!}
</span>
@endforeach
您认为会出现什么问题?你认为我做错了展示还是?
【问题讨论】:
-
我在页面上发布 cmets 时遇到问题 什么问题。我有问题对我们帮助你真的没有任何帮助。请告诉我们您有什么问题
-
1.在控制器 2 中将
comment重命名为comments。在视图中将$post->comments更改为$comments
标签: php html mysql laravel laravel-blade