laravel - 试图获得一个可变分页来向我展示 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。
解决方案
我目前已经完全改变了分页。我写了一个网址
/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);
推荐阅读
- javascript - Leaflet/Omnivore - 带有自定义弹出窗口的多个 GPX 轨道
- c++ - 从二进制 dll 中删除 protobuf-lite C++ 编译路径字符串
- vue.js - vue.js img 如何从随机 API 显示
- c - 递归 Dec 到 Bin 函数并将结果保存在 C 语言中的字符串中
- pandas - 从数据库中获取数据时,Dask 数据框仅返回列名,但不返回数据
- java - 如果数据输入错误,如何创建对话框?
- c# - 通过远程会话将 Exchange 命令行管理程序与 C# 一起使用时防止反序列化
- python - 将 img 路径从客户端传递到服务器烧瓶
- c# - DocFx 无法在 Azure Pipelines 上加载 System.Buffers.dll
- python - 减法矩阵