我有多个内容,每个内容都有多个注释,我想为每个内容显示一些注释,并允许用户单击以查看更多内容 我有此代码:
@foreach ($content as $content)
<div class="content">
...
</div>
@php($comments = $content->comments()->paginate(3))
@foreach ($comment as $comments)
<div class="content">
...
</div>
@endforeach
{!! $comments->render() !!}
@endforeach
{!! $content->render() !!}
问题是它不起作用,我什至试图为分页指定第三个参数,但是这会导致页面打开异常,其中包含所有内容和所有注释。 你能帮我解决这个问题吗?谢谢
答案 0 :(得分:0)
您将value
与array
/ object
相同的名称进行了更改,并关闭了@endphp
的标签,并将$comment->render()
放入了inderer foreach中,请尝试像这样
@foreach ($content as $c)
<div class="content">
...
</div>
@php
$comments = $c->comments()->paginate(3))
@endphp
@foreach ($comments as $comment)
<div class="content">
...
</div>
{!! $comment->render() !!}
@endforeach
@endforeach
{!! $content->render() !!}
将$content
更改为$contents
或更易读,然后使用like
@foreach ($contents as $content)