Laravel 在视图中获取带参数的路由

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23083035/
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-09-14 09:21:45  来源:igfitidea点击:

Laravel get route with parameter in view

phplaravellaravel-4laravel-routing

提问by Marek123

I need to get the route in my view for redirecting.

我需要在我的视图中获取路线以进行重定向。

Right now I'm doing this:
Laravel 4 - Get Current Route Name on Hidden Input to use for search

现在我正在这样做:
Laravel 4 - 在隐藏输入上获取当前路线名称以用于搜索

{{ Form::hidden('route', Route::current()->getUri()) }}  

Problem is, it looks like this when I get on a page with an id:

问题是,当我进入一个带有 id 的页面时,它看起来像这样:

<input name="route" type="hidden" value="recipes/details/{id}">  

How can I parse the {id} variable?

如何解析 {id} 变量?

回答by The Alpha

You should use:

你应该使用:

Request::url();

Instead of Route::current()->getUri(), but it's not proper way to redirect from the View, you should redirect from your Controllerinstead.

代替 Route::current()->getUri(),但它不是从 重定向的正确方法View,您应该从您的Controller改为重定向。

It should be in your case (for full url):

它应该在您的情况下(对于完整网址):

 // 'http://example.com/recipes/details/10'
{{ Form::hidden('route', Request::url()) }}

or use this (only for path):

或使用此(仅用于路径):

 // 'recipes/details/10'
{{ Form::hidden('route', Request::path()) }}