I am trying to create a page where I can see all the people in my database and create edits on them. I made a form where I fill in the data from the database of certain fields.
I would like to navigate trough them by a Next and Previous button.
For generating the next step I have to take the ID larger than the current one to load the next profile.
For generating the previous step I have to take the ID smaller than the current one to load the previous profile.
My route:
Route::get('users/{id}','UserController@show');
Controller:
public function show($id)
{
$input = User::find($id);
// If a user clicks next this one should be executed.
$input = User::where('id', '>', $id)->firstOrFail();
echo '<pre>';
dd($input);
echo '</pre>';
return View::make('hello')->with('input', $input);
}
View: The buttons:
<a href="{{ URL::to( 'users/' . $input->id ) }}">Next</a>
What is the best approach to get the current ID and increment it?
firstOrFail
could end up being an issue: when the user gets to view the last model, rather than being able to see it they get a 404 page, just because there's no 'next' model available. – alexrussell Feb 20 '14 at 13:51