Pagination with cache in Laravel

好久不见. 提交于 2020-05-28 08:05:14

问题


Can anyone help me? I use redis cache. But I see same results on every pages when I use pagination. How can I fix it? Thanks.


回答1:


You should cache your results per page, with a key that is the current page.

$currentPage = request()->get('page',1);

$category = Cache::remember('sellcategory-' . $currentPage, 10, function(){
    return DB::table('elans')->orderBy('updated_at', 'desc')->where(['derc' => 1,'elaninnovu' => 'Satılır'])->paginate(10);
});


来源:https://stackoverflow.com/questions/41976933/pagination-with-cache-in-laravel

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