laravel get next record

Solutions on MaxInterview for laravel get next record by the best coders in the world

showing results for - "laravel get next record"
Filippo
20 Jan 2018
1public function show($id)
2{
3
4    // get the current user
5    $user = User::find($id);
6
7    // get previous user id
8    $previous = User::where('id', '<', $user->id)->max('id');
9
10    // get next user id
11    $next = User::where('id', '>', $user->id)->min('id');
12
13    return View::make('users.show')->with('previous', $previous)->with('next', $next);
14}