php - Redirecting issue to a random id in Laravel -
in laravel 4.2 have route defined this:
route::get('author/{id}/edit', ...);
when tried redirect link random id previous 1 failed:
return redirect::to('author/{id}'); // or return redirect::to('author/(:any)');
but works when use redirect id manually like:
return redirect::to('author/8'); // or return redirect::to('author/9');
how redirect random id or how use redirect parameters?
best practice use named routes, way can point named route. when url changes, application still work based on name of route. in case, use:
route::get('author/{id}/edit', ['as' => 'author.edit', 'uses' => 'authorcontroller@edit']);
this way name of route 'author.edit'.
when try redirect route, can use redirect::route('author.edit', $authorid);
i tested this, , works random id, example:
return redirect::route('author.edit', rand());
Comments
Post a Comment