I'm creating a multi page form with Laravel. Now I have to provide switching between pages with previous and next buttons. What is the best practice to do that? Is there a better way than my following code?
I will have to create such a redirection route and function for each page. That seems a bit heavy-handed for me and doesn't follow the DRY-principle.
The router:
Route::post( '/test/redirect', array(
'as' => 'test.redirect',
'uses' => 'SettingsController@redirect'
) );
The relevant function in the controller MyController.php
public function redirect(Request $request) {
if ($request->has('next'))
{
return 'next';
// TODO: add validation and redirect to the next page.
}
else if ($request->has('back'))
{
return 'back';
// TODO: add validation and redirect to the previous page.
}
}
Template File: test.blade.php
{{ Form::open( array('route' => 'test.redirect', 'method' => 'post')) }}
{{ Form::submit( 'Back', array('name' => 'back')) }}
{{ Form::submit( 'Next', array('name' => 'next')) }}
{{ Form::close() }}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire