Laravel-禁用“选择计数"使用分页法加载时 [英] Laravel - Disable the "select count" on load when using paginate method

查看:180
本文介绍了Laravel-禁用“选择计数"使用分页法加载时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一个旧数据库(超文件)导入mysql以使用Laravel创建一个新应用.

I import an old database (hyperfile) to mysql to create a newapp with Laravel.

我使用的是分页方法内置的Laravel,但是第一个查询"select count(*)"需要大约10秒钟的时间来回答,因为此表中大约有70000行.

I'm using Laravel built in paginate method, but the first query "select count(*)" takes about 10 seconds to answer because there's about 70000 lines in this table.

我真的不需要知道有多少页...只需两个按钮上一个/下一个"就足够了. 有没有避免这种查询的方法?

I don't really need to know how many pages are present...just two buttons "previous/next" should be enough. Is there a method to avoid this query ?

推荐答案

https://laravel.com/docs/5.2/pagination

简单分页"

如果您只需要显示简单的下一步",和上一个"在分页视图中的链接中,您可以选择使用simplePaginate方法来执行更有效的查询.如果在渲染视图时不需要为每个页码显示链接,这对于大型数据集将非常有用:

If you only need to display simple "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 very useful for large datasets if you do not need to display a link for each page number when rendering your view:

$users = DB::table('users')->simplePaginate(15);

这篇关于Laravel-禁用“选择计数"使用分页法加载时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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