duanchi6397
duanchi6397
2014-04-15 11:57

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

已采纳

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

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

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

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

How can I parse the {id} variable?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • duanche8554 duanche8554 7年前

    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 Controller instead.

    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()) }}
    
    点赞 评论 复制链接分享