获取当前路径 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
get current path Laravel 5
提问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 Laravel
does 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 Laravel
that 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 Request
class, 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'];