laravel仅显示分页中的下一个和上一个链接 [英] laravel show only next and previous link in pagination

查看:368
本文介绍了laravel仅显示分页中的下一个和上一个链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Laravel分页功能,我只想显示上一个和下一个链接,而没有数字1 2 3 ...

I ma trying to use Laravel Pagination and I only want to show the Previous and Next link with out the number 1 2 3 ...

我该怎么做?我关注了Laravel页面: 简单分页"

how could I do that? I followed Laravel page : "Simple Pagination"

如果在分页视图中仅显示下一个"和上一个"链接,则可以选择使用simplePaginate方法执行更有效的查询.当您不需要在视图上显示确切的页码时,这对于较大的数据集很有用:

If you are only showing "Next" and "Previous" links in your pagination view, you have the option of using the simplePaginate method to perform a more efficient query. This is useful for larger datasets when you do not require the display of exact page numbers on your view:

$someUsers = User::where('votes', '>', 100)->simplePaginate(15);

但是当我在视图中执行此操作时,它仍显示页码:

but this still shows the page number when I do this in my view:

<?php echo $someUsers->links(); ?>

任何人都可以帮忙

谢谢

推荐答案

tldr;您想对分页器(在视图中)的查询 AND links('some.view')上使用simplePaginate()方法,以实现您的要求.

tldr; you want to use simplePaginate() method on the query AND links('some.view') on the paginator (in the view) in order to achieve what you ask for.

这是在给定模板中显示所选链接所需要的:

Here's what you need in order to show chosen links in given template:

// inline choose simple links (prev, next)
{{ $someUsers->links('pagination::simple') }}

// inline choose slider links
{{ $someUsers->links('pagination::slider') }}

// inline choose slider-3 (default)
{{ $someUsers->links('pagination::slider-3') }}

这些是框架的模板,位于laravels目录中:Illuminate/Pagination/views/

These are framework's templates, placed in laravels directory: Illuminate/Pagination/views/

您始终可以决定使用自定义模板,为此只需调用:

You can always decide to use your custom templates, for this simply call:

// assuming you have it in app/views/pagination/my-links.blade.php
{{ $someUsers->links('pagination.my-links') }}

// or using views namespace (you need to define it first)
{{ $someUsers->links('myNamespace::my-links') }}


您当然可以在app/config/view.php中将链接定义为默认链接:


Of course you can define your links as default in app/config/view.php:

// instead of
'pagination' => 'pagination::slider-3',

// something like
'pagination' => 'pagination.my-links',

这篇关于laravel仅显示分页中的下一个和上一个链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆