获取当前路径 Laravel 5

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

get current path Laravel 5

phplaravellaravel-5routes

提问by Jos Koomen

I've tried to find the full path of current route in Laravel 5.x

我试图找到当前路线的完整路径 Laravel 5.x

For this case i've created a method with the following code, but i can't imagine that Laraveldoes not provide something like this themselves:

对于这种情况,我使用以下代码创建了一个方法,但我无法想象它Laravel自己不提供这样的东西:

 $current = Route::getFacadeRoot()->current();
 $uri = $current->uri();
 foreach ($current->parameters() as $key => $param) {
     $uri = str_replace('{' . $key . '}', $param, $uri);
 }
 return url($uri);

Is there something out of the box in Laravelthat i just can't find?

有什么开箱即用的东西Laravel我找不到吗?

回答by kscorrales

you can use

您可以使用

Request::url()

blade:

刀刃:

{{\Request::url()}} // if is in blade

回答by Martin Bean

Laravel has a handy method on the Requestclass, coincidentally, called fullUrl():

Laravel 在Request类上有一个方便的方法,巧合的是,称为fullUrl()

Request::fullUrl();

This is covered in the Laravel documentation: https://laravel.com/docs/master/requests#accessing-the-request

这在 Laravel 文档中有介绍:https://laravel.com/docs/master/requests#accessing-the-request

回答by Alexey Mezenin

Try this clause:

试试这个条款:

URL::current();

Or:

或者:

$request->url();

Or PHP way:

或 PHP 方式:

$_SERVER['REQUEST_URI'];