首页 > 解决方案 > 试图获得一个可变分页来向我展示 3 种不同类型的分页

问题描述

这是我的索引:

<div class="page-sizer">
                <a class="page numbers" href="{{$references->pagination(10)}}">10</a>
                <a class="page numbers" href="{{$references->pagination(30)}}">30</a>
                <a class="page numbers" href="{{$references->pagination(100)}}">100</a>
                <button  href="qweqwe.qweqwe" class="btn btn-info float-right>112e1e1e1e"></button>
                </div>

我的管理员参考控制器:

 public function index()
    {
        $references = Reference::orderBy('priority', 'desc')->orderBy('id', 'desc')->paginate(50);

        return view('admin.reference.index', ['references' => $references]);

    }

和我的 Lengthawarepaginator:

public function __construct($items, $total, $perPage, $currentPage = null, array $options = [])
    {
        foreach ($options as $key => $value) {
            $this->{$key} = $value;
        }

        $this->total = $total;
        $this->perPage = $perPage;
        $this->lastPage = max((int) ceil($total / $perPage), 1);
        $this->path = $this->path !== '/' ? rtrim($this->path, '/') : $this->path;
        $this->currentPage = $this->setCurrentPage($currentPage, $this->pageName);
        $this->items = $items instanceof Collection ? $items : Collection::make($items);
    }

. 我目前收到错误 Method Illuminate\Database\Eloquent\Collection::pagination 不存在。我想要 3 个按钮来显示 3 种不同类型的分页,例如底部搜索栏中的 stackoverflow。

标签: laravelpaginationbackendlaravel-5.7

解决方案


我目前已经完全改变了分页。我写了一个网址

/x/y/perpage/10,
/x/y/perpage/30,
/x/y/perpage/100,

我为它开辟了一条新路线

route::('/x/perpage/{count})'

并将我的 AdminReferenceController 更改为

public function index($perpage = false)
    {
        if(!$perpage) {
            $perpage = 10;
        }
        $references = Reference::orderBy('priority', 'desc')->orderBy('id', 'desc')->paginate($perpage);

推荐阅读