How to get the next and previous entries in a collection in a controller? #8193
Answered
by
floristenhove
floristenhove
asked this question in
Q&A
-
I'd like to get the previous and next entries in an ordered collection in a controller, based on the current entry. I know how to do this using the |
Beta Was this translation helpful? Give feedback.
Answered by
floristenhove
May 25, 2023
Replies: 1 comment
-
I have solved it this way: // an $entry has been fetched...
$previous = $entry->where('order', '<', $entry->order)->last();
$next = $entry->where('order', '>', $entry->order)->first(); Let me know if there's a better approach 👍🏻 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
floristenhove
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have solved it this way:
Let me know if there's a better approach 👍🏻