我正在开发一个Laravel 5应用程序,我有一条路线Route::get('states/{id}/regions', ['as' => 'regions', 'uses' => 'RegionController@index']);
在我的控制器中,在我正确地进行了post调用之后,我想重定向到那个视图,使用以下命令:
return \Redirect::route('regions')->with('message', 'State saved correctly!!!');
问题是我不知道如何传递{id}参数,它应该在我的URL中。
- 谢谢-谢谢
8条答案
按热度按时间nx7onnlm1#
您可以将路由参数作为第二个参数传递给
route()
:如果只有一个,也不需要写成数组:
如果布线具有多个参数,或者只有一个参数,但您希望明确指定每个参数具有哪个值(为了便于阅读),则始终可以执行以下操作:
idfiyjo82#
您仍然可以这样做:
如果有多个参数,可以将参数作为数组传递,例如:假设您必须在路线中经过特定地区的首都,则您的路线可能类似于以下内容:
然后可以使用以下命令重定向:
4bbkushb3#
在laravel中重定向此URL有几种方法:
1.将URL与全局重定向帮助器函数一起使用
1.使用命名路由
1.使用控制器动作
trnvg8h34#
您可以使用以下
或
izj3ouym5#
您可以使用如下重定向传递{id}参数
5fjcxozz6#
如果路由器包含这样的内容:
在控制器中可以这样进行重定向
dluptydi7#
您可以在外部为变量赋值url和id,然后在redirect内部调用它。
rdlzhqv98#
上面的答案已经显示了多种方法来做。只是增加了另一种方法来实现在紧凑的方式。
按顺序传递和按相同顺序访问。