Razvan's avatar

Eloquent custom pagination similar to Reddit's

The normal laravel/eloquent (simple) pagination will use pages and can be achieved by doing something like this:

$posts = Post::with(array('user'=>function($q){
            $q->select('id', 'img','nick', 'points', 'slug');
        }))->with('categories')
        ->with('voted')
        ->orderBy('rank', 'DESC')
        ->orderBy('created_at','DESC')
        ->simplePaginate(20);
        return view('layouts.home')->with('posts',$posts);

this will use an url with a ?page=pageNo argument. Because the ranking changes quite fast, what I really want is to be able to get the following or previous posts after a certain post identified by an id or hashId. This is the way reddit does it:

https://www.reddit.com/?count=25&after=t3_4g1n0n
0 likes
0 replies

Please or to participate in this conversation.