Laravel - Disable the “select count” on load when using paginate method

一个人想着一个人 提交于 2020-07-11 04:46:23

问题


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

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 ?


回答1:


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

"Simple Pagination"

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);


来源:https://stackoverflow.com/questions/37729226/laravel-disable-the-select-count-on-load-when-using-paginate-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!