php Laravel:从控制器重定向到 URL 中带有婴儿车的命名路由

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21079280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:48:33  来源:igfitidea点击:

Laravel: redirect from controller to named route with prams in URL

phplaravel

提问by Kris

how can I redirect from my controller to a named route and include variables in the URL, e.g.

如何从我的控制器重定向到命名路由并在 URL 中包含变量,例如

return Redirect::to('admin/articles/create/'.$article_type.'/'.$area_id.'/'.$area_type);

this works, but I think that I missed a shortcut or something?

这有效,但我想我错过了捷径之类的?

回答by Marwan

In Laravel 5, you can use the helper methods:

在 Laravel 5 中,您可以使用辅助方法:

return redirect()->route('route.name', [$param]);

回答by Altrim

You can use Redirect::route()to redirect to a named route and pass an array of parameters as the second argument

您可以使用Redirect::route()重定向到命名路由并将参数数组作为第二个参数传递

 Redirect::route('route.name',array('param1' => $param1,'param2' => $param2))

Hope this helps.

希望这可以帮助。

回答by Alemoh Rapheal Baja

You can try this :

你可以试试这个:

return redirect()->route('profile', [$user]);

This can help also if you are trying to redirect user to a profile with the id.

如果您尝试将用户重定向到带有id.