laravel 5.5.40分页内部分页

时间:2018-09-03 12:13:33

标签: laravel pagination

我有多个内容,每个内容都有多个注释,我想为每个内容显示一些注释,并允许用户单击以查看更多内容 我有此代码:

    @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() !!}

问题是它不起作用,我什至试图为分页指定第三个参数,但是这会导致页面打开异常,其中包含所有内容和所有注释。 你能帮我解决这个问题吗?谢谢

1 个答案:

答案 0 :(得分:0)

您将valuearray / 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)