Laravel previous and next records

Below are your updated controller and view files derived from @ridecar2 link,

Controller:

public function show($id)
{

    // get the current user
    $user = User::find($id);

    // get previous user id
    $previous = User::where('id', '<', $user->id)->max('id');

    // get next user id
    $next = User::where('id', '>', $user->id)->min('id');

    return View::make('users.show')->with('previous', $previous)->with('next', $next);
}

View:

<a href="https://stackoverflow.com/questions/21909706/{{ URL::to("users/' . $previous ) }}">Previous</a>
<a href="https://stackoverflow.com/questions/21909706/{{ URL::to("users/' . $next ) }}">Next</a>

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)