chim0r's avatar

Caching and Pagination without $request

Hey there,

this is my route:

Route::get('/', 'KategorieController@gesamt');

and this is my code:

        $links = Cache::remember('gesamt', 30, function() use ($aktivkat) {
        return Artikel::whereIn('author', $aktivkat)->where('status','publish')->orWhere('copyright', 'user')->where('status','publish')->latest()->inRandomOrder()->paginate(10);
        });

how to cache this with a working pagination? - i only get the first page back.

Thank you

0 likes
1 reply
chim0r's avatar
chim0r
OP
Best Answer
Level 6

I fixed it by myself :)

add:

$currentPage = isset($_GET["page"]) ? (int)$_GET["page"] : 1;

and edit code to:

$links = Cache::remember('gesamt_' . $currentPage, 30, function() use ($aktivkat) {
return Artikel::whereIn('author', $aktivkat)->where('status','publish')->orWhere('copyright', 'user')->where('status','publish')->latest()->inRandomOrder()->paginate(10);
        });

Please or to participate in this conversation.