Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
[5.8] Add forPageBeforeId method to query builder #28011
On my current project, I have the need in the admin area to show a chat post in context of its surrounding posts. This allows admins to view a specific chat post that has been reported for abuse (or other potential issues) within context of the chat thread.
The following is a (terrible) example of what I mean just to illustrate the point.
I stumbled upon the existing
This PR introduces the complementary method
This allows a developer to do something like this...
$posts = new Collection; $posts = $posts->concat(ChatPost::forPageBeforeId(15, $focused->id)->get()->reverse()); $posts = $posts->push($focused); $posts = $posts->concat(ChatPost::forPageAfterId(15, $focused->id)->get());
which results in a collection of posts that contain the focused post, with 15 posts on either side of the focused post, sorted chronologically.
It’s great to discover new methods like this. “Page before” and “page after” would be handy for cursor-like pagination.
I’m thinking about the naming though. If the column to page before/after is configurable, something like