N
N
Nubbb2020-06-15 00:19:14
Laravel
Nubbb, 2020-06-15 00:19:14

Pagination while caching in Laravel?

how to return pagination when caching a request?

$posts = Cache::remember('posts', Carbon::now()->addHour(), function () {
            return Post::where('language_id','=', 1)->orderBY('id','DESC')->paginate(12);
        });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d0ark, 2020-06-15
@d0ark

Try

$page = $request->get('page', 1);
$posts = Cache::remember('posts.' . $page, Carbon::now()->addHour(), function () {
            return Post::where('language_id','=', 1)->orderBY('id','DESC')->paginate(12);
        });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question