Created
April 25, 2013 07:02
-
-
Save ermand/5458012 to your computer and use it in GitHub Desktop.
Get Previus Next Record in Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Get the current user that will be the origin of our operations | |
$currentUser = User::find(10); | |
// Get ID of a User whose autoincremented ID is less than the current user, but because some entries might have been deleted we need to get the max available ID of all entries whose ID is less than current user's | |
$previousUserID = User::where('id', '<', $currentUser->id)->max('id'); | |
// Same for the next user's id as previous user's but in the other direction | |
$nextUserID = User::where('id', '>', $currentUser->id)->min('id'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment