【问题标题】:How to add Pagination in laravel 5如何在 laravel 5 中添加分页
【发布时间】:2023-03-18 01:43:01
【问题描述】:

我需要每页显示一行。 这是我的控制器类代码

public function showcontent($id)
{
    $story=storybook::find($id);
    $content=storycontent::where('titleid', $story['id'])->paginate(1);
    //return $content;
    return view('storyBook/viewStory',compact('story','content'));
}

这是我的视图类代码

 @foreach($content as $content)
            <?php $a=null; ?>
            <?php $b=null; ?>

                <?php $a=$content->file1; ?>
                <?php $b=$content->file2; ?>

            <table style="height: 330px;width: 680px;margin-top: 120px;margin-left: 50px">
                <tr>
                    <td style="width: 340px"><img src="/{{$a}}" alt="Mountain View" style="width:330px;height:300px;"></td>
                    <td style="width: 340px"><img src="/{{$b}}" alt="Mountain View" style="width:330px;height:300px;"></td>
                </tr>
            </table>
            <br>
        @endforeach

在这里我只得到第一行,其余行不可见.. 我不知道如何添加分页。

【问题讨论】:

  • 每页只有一行??
  • 我得到了不止一行 $content..但我需要每页显示一行..

标签: laravel-5 pagination


【解决方案1】:

@foreach($content as $content)

所以首先改变 vars 的命名例如:

@foreach($content as $entry)
    <table style="height: 330px;width: 680px;margin-top: 120px;margin-left: 50px">
        <tr>
            <td style="width: 340px"><img src="/{{$entry->file1}}" alt="Mountain View" style="width:330px;height:300px;"></td>
            <td style="width: 340px"><img src="/{{$entry->file2}}" alt="Mountain View" style="width:330px;height:300px;"></td>
        </tr>
    </table>
    <br>
@endforeach

$content->links()

如您所见,我在 foreach 循环之后添加了 $content-&gt;links()。这是Paginator打印分页导航的方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-14
    • 1970-01-01
    • 2020-10-12
    • 2018-07-03
    • 2017-11-30
    • 2021-06-06
    • 1970-01-01
    • 2016-12-10
    相关资源
    最近更新 更多