Hello.
I currently work on creating a site that draws forum posts out onto a separate page where i use them as blog entries. In order to make it work as i want, i first ->get() the newest post for the top, main, blog entry, and then i foreach the others underneath it with masonry style like this : www.hockeyforat.se/laravel
This means that i do have this set up:
$post = Post::whereNewTopic(true)
->whereHas('Topic', function($q){$q->whereForumId(13);})
->orderBy('pid', 'DESC')
->first();
$vars['p'] = $post;
And this obviously is meant to drag out the newest post and put it on top, so that works great, but then comes the other part where i have to skip the first post (as it is already on the page per above code). I used this to do that:
$posts = Post::whereNewTopic(true)
->whereHas('Topic', function($q){$q->whereForumId(13);})
->orderBy('pid', 'DESC')
->skip(1)
->take(100000)
->get();
$vars['posts'] = $posts;
And this worked supremely too. But when i wanted to paginate it, i had some issues.. For some reason my ->paginate(6) ignores the ->skip(1). Anyone knows how to get around this? Example is here again : www.hockeyforat.se/laravel and I'll also add a picture below. As you can see, without skipping the first, I will get the same post in a row due to the first one being drawn out with $post here above.
$posts = Post::whereNewTopic(true)
->whereHas('Topic', function($q){$q->whereForumId(13);})
->orderBy('pid', 'DESC')
**->skip(1)**
->take(100000)
**->paginate(6);**
$vars['posts'] = $posts;
Couldnt get the skip part to work with paginate as intended but it was solved by saying "Do not paginate whatever post id (pid) that is in $post.
$post = Post::whereNewTopic(true)
->whereHas('Topic', function($q){$q->whereForumId(13);})
->orderBy('pid', 'DESC')
->first();
$vars['p'] = $post;
$posts = Post::whereNewTopic(true)
->whereHas('Topic', function($q){$q->whereForumId(13);})
->where('pid', '<>', $post->pid)
->orderBy('pid', 'DESC')
->paginate(6);
$vars['posts'] = $posts;