laravel 框架给数组分页

Posted 阳光小白

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了laravel 框架给数组分页相关的知识,希望对你有一定的参考价值。

        //Get current page form url e.g. &page=6
        $currentPage = LengthAwarePaginator::resolveCurrentPage();

        $currentPage -= 1;

        //Create a new Laravel collection from the array data
        $collection = new Collection($log_data[‘content‘]);

        //Define how many items we want to be visible in each page
        $perPage = 10;

        //Slice the collection to get the items to display in current page
        $currentPageSearchResults = $collection->slice($currentPage * $perPage, $perPage)->all();

        //Create our paginator and pass it to the view
        $paginatedSearchResults= new LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage);

        $url = url(‘admin/statistics/index‘);

        $paginatedSearchResults = $paginatedSearchResults->setPath($url);




















以上是关于laravel 框架给数组分页的主要内容,如果未能解决你的问题,请参考以下文章

laravel手动数组分页

Laravel框架——分页

Laravel 分页不适用于数组而不是集合

laravel框架实现ajax分页

[ Laravel 5.5 文档 ] 数据库操作 —— 在 Laravel 中轻松实现分页功能

laravel 手动分页 我分的是数组